Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 3477
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 2, 20222022-06-02T16:30:54+00:00 2022-06-02T16:30:54+00:00

regex – I need to improve my Powershell Regular Expression to find Java codes for specific System.out.println patterns

  • 0

[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]

  • 0 0 Answers
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8056 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1842 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1924 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.