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 991133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:03:32+00:00 2026-05-16T06:03:32+00:00

I need some help to model this regular expression. I think it’ll be easier

  • 0

I need some help to model this regular expression. I think it’ll be easier with an example. I need a regular expression that matches a comma, but only if it’s not inside this structure: "( )", like this:

,a,b,c,d,"("x","y",z)",e,f,g,

Then the first five and the last four commas should match the expression, the two between xyz and inside the ( ) section shouldn’t.

I tried a lot of combinations but regular expressions is still a little foggy for me.

I want it to use with the split method in Java. The example is short, but it can be much more longer and have more than one section between “( and )”. The split method receives an expression and if some text (in this case the comma) matches the expression it will be the separator.

So, want to do something like this:

String keys[] = row.split(expr);
System.out.println(keys[0]); // print a
System.out.println(keys[1]); // print b
System.out.println(keys[2]); // print c
System.out.println(keys[3]); // print d
System.out.println(keys[4]); // print "("x","y",z)"
System.out.println(keys[5]); // print e
System.out.println(keys[6]); // print f
System.out.println(keys[7]); // print g

Thanks!

  • 1 1 Answer
  • 2 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-05-16T06:03:33+00:00Added an answer on May 16, 2026 at 6:03 am

    You can do this with a negative lookahead. Here’s a slightly simplified problem to illustrate the idea:

    String text = "a;b;c;d;<x;y;z>;e;f;g;<p;q;r;s>;h;i;j";
    
    String[] parts = text.split(";(?![^<>]*>)");
    
    System.out.println(java.util.Arrays.toString(parts));
    //  _  _  _  _  _______  _  _  _  _________  _  _  _
    // [a, b, c, d, <x;y;z>, e, f, g, <p;q;r;s>, h, i, j]
    

    Note that instead of ,, the delimiter is now ;, and instead of "( and "), the parentheses are simply < and >, but the idea still works.


    On the pattern

    The […] is a character class. Something like [aeiou] matches one of any of the lowercase vowels. [^…] is a negated character class. [^aeiou] matches one of anything but the lowercase vowels.

    The * repetition specifier can be used to match “zero-or-more times” of the preceding pattern.

    The (?!…) is a negative lookahead; it can be used to assert that a certain pattern DOES NOT match, looking ahead (i.e. to the right) of the current position.

    The pattern [^<>]*> matches a sequence (possibly empty) of everything except parentheses, finally followed by a paranthesis which is of the closing type.

    Putting all of the above together, we get ;(?![^<>]*>), which matches a ;, but only if we can’t see the closing parenthesis as the first parenthesis to its right, because witnessing such phenomenon would only mean that the ; is “inside” the parentheses.

    This technique, with some modifications, can be adapted to the original problem. Remember to escape regex metacharacters ( and ) as necessary, and of course " as well as \ in a Java string literal must be escaped by preceding with a \.

    You can also make the * possessive to try to improve performance, i.e. ;(?![^<>]*+>).

    References

    • regular-expressions.info/Character class, Repetition, Lookarounds, Possessive
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with this one.... I have this simple model: public class
I'm creating a Trivia app, and need some help designing my model relationships. This
I need some help guys, trying to make this test to pass but with
Need some help with Activerecord Querying in a has_many :through association. Model: Job class
Need some help to solve this. I have a gridview and inside the gridview
Need some help with this problem in implementing with XSLT, I had already implemented
Need some help gathering thoughts on this issue. Our team is moving ahead with
Need some help assigning a mouseover event to display some icons that start out
Need some help with DataFormatString in GridView. I have a Double value that needs
I need some help over here to understand how the model relationship works on

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.