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 a 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

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7808031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:02:03+00:00 2026-06-02T03:02:03+00:00

I am using regex to go through some VB code and I want to

  • 0

I am using regex to go through some VB code and I want to find statements of the form –

    ABC.Transaction = GlobalCommArea

Unfortunately, some statements are commented out in the code. VB single line comments begin with a single quote, so my search gives results like –

        ' ABCD.Transaction = GlobalCommArea    <-- incorrect
  ' PQR.Transaction = GlobalCommArea           <-- incorrect
  WXY.Transaction = GlobalCommArea             <-- correct
      WXY.Transaction = GlobalCommArea ' 2012      <-- correct

I tried to detect for the presence of a single quote and exclude it, using the following code –

     public static void test2()
     {
    String[] lines = new String[20];

  lines[0] = "' ABCD.Transaction = GlobalCommArea";
  lines[1] = "   ' PQR.Transaction = GlobalCommArea";
  lines[2] = " WXY.Transaction = GlobalCommArea";
  lines[3] = "WXY.Transaction = GlobalCommArea ' 2012";

  String regex;
  regex = "^\\s*[^']*\\s*.*.Transaction\\s*=\\s*GlobalCommArea"; // the regex that I am using

      Pattern p = Pattern.compile(regex);


  for(int i=0; i<=3; i++)
  {
     Matcher m = p.matcher(lines[i]);

     if(m.find())
     {
        System.out.print("Yes\t");
     }
     else
     {
        System.out.print("No\t");
     }

      System.out.println(lines[i]);
     }
    }

However, the regex didn’t work. I got the following output –

    Yes ' ABCD.Transaction = GlobalCommArea
    Yes    ' PQR.Transaction = GlobalCommArea
    Yes  WXY.Transaction = GlobalCommArea
    Yes WXY.Transaction = GlobalCommArea ' 2012

How to write a regex that will detect the single quote at the beginning of the line (i.e. excluding whitespace) and avoid those lines?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:02:04+00:00Added an answer on June 2, 2026 at 3:02 am

    You are matching all of them because of the .* before Transaction, try changing it to the following:

    regex = "^[^']*\\.Transaction\\s*=\\s*GlobalCommArea";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help using regex in java. Im trying to achieve 2 different
I want to validate below data using regex and python. Below is the dump
i want to check 2 patterns using regex. can i check those both patterns
I have some JavaScript, which is generated by PHP code, using a template. The
I'm trying to write some replacement regex that will insert a locale code into
I am using a while(matcher.find()) to loop through all of the matches of a
While using regex to help solve a problem in the Python Challenge , I
I have to validate using regex decimal number between 00.00 to 35.35 with following
I am using regex in C# I need to parse a string till it
I'm using regEx and replace method to replace an empty space with a dash

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

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.