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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:18:32+00:00 2026-05-14T00:18:32+00:00

i search for a regex to split the following string: aaa[bbb,ccc[ddd,{eee:1,mmm:999}],nnn[0,3]] aaa[bbb,ccc[ddd,{eee:1, mmm:[123,555]}],nnn[0,3]] aaa[bbb,

  • 0

i search for a regex to split the following string:

aaa[bbb,ccc[ddd,{eee:1,mmm:999}],nnn[0,3]]
aaa[bbb,ccc[ddd,{eee:1, mmm:[123,555]}],nnn[0,3]]
aaa[bbb, ccc[ddd, ddd],nnn[0,3]]
aaa[bbb,ddd[0,3]]

by ‘[‘ or ‘]’ or ‘,’ unless the ‘,’ is in ‘{}’. As example: split ‘aaa[bbb,ccc[ddd,’ to aaa, bbb, ccc, ddd is allow but not {eee:1,mmm:999}.

the result:

aaa, bbb, ccc, ddd, {eee:1,mmm:999}, nnn, 0, 3
aaa, bbb, ccc, ddd, {eee:1, mmm:[123,555]}], nnn, 0, 3
aaa, bbb, ccc, ddd, ddd, nnn, 0, 3
aaa, bbb, ddd, 0, 3

i have read meany other questions but i cant modifie the regex’s there are post to do this what i want.

the target language for the expression is javascript.

  • 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-05-14T00:18:32+00:00Added an answer on May 14, 2026 at 12:18 am

    Perl/PCRE regex, should work in JS too (as long as {} aren’t nested):

    $_ = 'aaa[bbb,ccc[ddd,{eee:1,mmm:999}],nnn[0,3]]
    aaa[bbb,ccc[ddd,{eee:1, mmm:[123,555]}],nnn[0,3]]
    aaa[bbb, ccc[ddd, ddd],nnn[0,3]]
    aaa[bbb,ddd[0,3]]';
    
    @r = /[^][,{}]+|\{[^}]*}/g;
    print join ", ", @r;
    

    Output:

    aaa, bbb, ccc, ddd, {eee:1,mmm:999}, nnn, 0, 3,
    aaa, bbb, ccc, ddd, {eee:1, mmm:[123,555]}, nnn, 0, 3,
    aaa, bbb,  ccc, ddd,  ddd, nnn, 0, 3,
    aaa, bbb, ddd, 0, 3
    

    A rough translation into JavaScript:

    var input =
        "aaa[bbb,ccc[ddd,{eee:1,mmm:999}],nnn[0,3]]\n" +
        "aaa[bbb,ccc[ddd,{eee:1, mmm:[123,555]}],nnn[0,3]]\n" +
        "aaa[bbb, ccc[ddd, ddd],nnn[0,3]]\n" +
        "aaa[bbb,ddd[0,3]]";
    
    var re = /[^][,{}]+|\{[^}]*}/g;
    
    var result = [];
    while (!!(match = re.exec(input)))
    {
        result.push(match[0]);
    }
    
    // Using <<value>> rather than just a comma, for clarity around
    // whether and how "{...}" was processed or not.
    write("<<" + result.join(">><<") + ">>");
    

    It’s not clear what the line breaks in the input or result data in the question are meant to be. In the above, they’re line breaks in the input data and then not treated specially in the result. If they need to be treated specially, the OP can edit appropriately. And so this is the result of the above (again, using << and >> as separators rather than , for clarity around whether {...} gets processed):

    <<aaa>><<bbb>><<ccc>><<ddd>><<{eee:1,mmm:999}>><<nnn>><<0>><<3>><<
    aaa>><<bbb>><<ccc>><<ddd>><<{eee:1, mmm:[123,555]}>><<nnn>><<0>><<3>><<
    aaa>><<bbb>><< ccc>><<ddd>><< ddd>><<nnn>><<0>><<3>><<
    aaa>><<bbb>><<ddd>><<0>><<3>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to search a string that is a regex, without escaping all
am new to regular expressions and i cant handle a regex search using grep..
I have a binary file that I would like to regex search/replace hex bytes
std::cmatch res; std::string str = <h2>I'm a piece of text</h2>; std::regex rx(<h(.)>([^<]+)); std::regex_search(str.c_str(), res,
I'm looking for a regex to search my python program to find all lines
Is there a way in Ant to just use regex to search through a
Another RegEx question for a search I'm trying to do. The Problem : Determine
I need to perform a regular expression search for a string x in another
I am trying to remove from a string using Regex. I am receiving a
I am attempting to search a directory for a given string pattern in Python.

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.