[ad_1]
We are trying to scan through a large library of files that have html, xml, and java files that can all include Java code for System.out.println. The issue is I need to find a specific set of examples of just that part of the code.
Example 1:
System.out.println("my job code is: " var.jobcode);
Example 2:
System.out.println("my jc is: " var.jc);
Example 3:
System.out.println("my jbc is: " var.jbc);
I have tried to get this with the following:
Get-ChildItem C:\my\folder\path -Recurse | Where-Object FullName -Match ".*C:\\my\\folder\\path*" | Where-Object FullName -Match ".*." | Select-String -Pattern '(System\.out\.println+(.*?job)\/?[^)]+[)]\s*;)|(System\.out\.println+(.*?jc)\/?[^)]+[)]\s*;)|(System\.out\.println+(.*?jbc)\/?[^)]+[)]\s*;){99}' -List | Select Path,Line
I got the files I wanted but I also get false positives so that files with the following lines are in the results by mistake.
System.out.println ("component printout: item"); System.out.println (""); <td style="word-break: break-all;word-wrap:break-word;font-size:12px;" class="FONTSTYLE" align="left">Job Codes</td><td style="word-break: break-all;word-wrap:break-word;font-size:12px;" class="FONTSTYLE" align="left">
So anytime a file has a System.out.println(); section followed by any word “job” that file gets picked up too when it shouldn’t.
I have to run this over several thousand files on a semi-regular basis and need to output the file path/name and line the offending code is in.
How can I clean up this Regex to be more specific to only include files with lines like my examples above but not pickup the other files?
[ad_2]