search thousands of strings in thousands of files

Asked

Viewed 115 times

0

I have the following problem: our system is parameterizable, and these parameters are in a table. But over the past 25 years, many programmers have tampered with the system and created and used these parameters without documenting them. That’s why I’m in this job of documenting that.

The first part is to locate all these parameters throughout the system code base, which is done in classic ASP, ASP.NET, C#, Delphi, Oracle pl/sql and Javascript.

I need to search more than 3500 strings in more than 20000 fonts, as far as possible eliminating false positives, which are field names equal to parameter names, internal variables with the same name as the parameters, etc, etc, etc., so I need to search for these more than 3500 strings ensuring that they are between plics ('), or between quotation marks (") or between spaces, tabs, dots, or at the beginning or end of the line.

I’m using a powershell script for this.

The expression below suits me in almost everything, except when the string appears at the beginning or at the end of the line:

(?sm)[\s\W]+WS_URL_CONSULTA_CNPJ_SERASA[\s\W\n]+

Any hints how I would include as a condition the above string appears at the beginning of the OR line at the end of the line? In these cases it would not be between plics or quotation marks.

  • You could use your regex with the following additions: ^(?sm)[\s\W]+WS_URL_CONSULTA_CNPJ_SERASA[\s\W\n]+ for strings started by your regex or (?sm)[\s\W]+WS_URL_CONSULTA_CNPJ_SERASA[\s\W\n]+$ for strings terminated with your regex.

  • Hello. Your suggestion does not solve the problem but gave me a hint to solve the problem: use several expressions. I did so: [ s W]+WS_URL_CONSULTA_CNPJ_SERASA[ s W]+|[ s W]+WS_URL_CONSULTA_CNPJ_SERASA[ s W]*$| [ s W]*WS_URL_CONSULTA_CNPJ_SERASA

1 answer

0

If you are sure that each parameter starts and ends with a word character ([0-9_a-zA-Z]), can use word limits \b.

$regex = [regex] "\b$( $WS_URL_CONSULTA_CNPJ_SERASA )\b"

$data -match $regex
"Encontrou: $($matches[0])"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.