Code

RegEx: Finding a function name with the parameter value in source code

I wanted to produce a list of all the following functions calls in order to get a list of the parameters to cross-check the setting exists in the database:

For Example:

The function name: GetSetting

It can contain one setting key parameter or an optional 2nd default parameter OR a nested GetSetting() to retrieve a default parameter.

RegEx Syntax

Using this regex I was able to find all the occurrences.

(GetSetting).("([^"]|"")*).

Source: https://www.regextester.com/3269

I found the following power shell script on Stack Overflow that will take a text file and produce a unique list (some clean up was needed in the output file, however, with some tweaking of the RegEx it should be able to produce a clean list.)  I took the search results that contained full lines of code and ran it through this power shell script:

 

select-string -Path d:\codegetsetting.txt -Pattern "([wGetSetting(""])([""'])(?:(?=(\?))2.)*?1" -AllMatches | % { $_.Matches } | select-object Value -unique | sort-object Value > d:\regexgetsettingresult.txt

 

Sample Results:

GetSetting(“AllowTextSearchingAndOr”, True)) Then

GetSetting(“AltLocationType”, “Folder”), True)
GetSetting(“AltLocJoinFieldName”)) Then                                         

GetSetting(“AltLocJoinTableName”)) AndAlso 

GetSetting(“AltLocJoinTableName”), True) = 0 Then

<cut for brevity>

Using Notepad++ I was able to clean up the results down to just the “parameter” list I needed.

Related Posts

Leave a thought

%d bloggers like this: