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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:11:07+00:00 2026-06-13T12:11:07+00:00

Say I have a string like item:(one|two|three), item2:(x|y) Is there a single regex that

  • 0

Say I have a string like

"item:(one|two|three), item2:(x|y)"

Is there a single regex that could “factor” it into

"item:one, item:two, item:three, item2:x, item2:y"

Or must I resort to splitting and looping?

If I must split it up then how do I even turn

"item:(one|two|three)"

into

"item:one, item:two, item:three"

if the amount of things between the parentheses is variable? Are regexes useless for such a problem?

  • 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-13T12:11:08+00:00Added an answer on June 13, 2026 at 12:11 pm

    You could do it with a callback function:

     str = str.replace(/(\w+):\(([^)]*)\)/gi, function(match,item,values)
         {return item + ':' + values.split("|").join(', '+item+':')}
     );
    

    For every item, the first parentheses in the regex capture the item’s name (i.e item) and the second set of (unescaped) parentheses capture the string of all values (i.e one|two|three). The latter are then split at | and joined together with , itemname: and then there is another item name appended to the beginning of the result.

    This is probably the easiest way to combine regexes to find your data and split and join to build your new regex. The problem why it is not easier is, that you cannot capture an arbitrary number of consecutive values (one|two|three) in different capturing groups. You would only get the last one, if you tried to capture them individually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

say I have a string like so Testing How could I have it remove
Let's say I have a string that I retrieve from a DB like: Lorem
There is a string that is being formulated something like this Item:ShortName:Tax and if
Say i have an object like class Item { string Value {get;set;} } class
So say I have a string like so of a path $path = '/path/to/../../up/something.txt';
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have a string like this: String test = hfikoebndolahsdHEL123LOkjahhsdqhuihs; And then
Let's say I have a string like this. Dim str As String = code
So lets say I have an string like so. $pizza = 1,2,3,5-4,7; and what
Say I have a few string like Hi my name is <Name> Hi <name>,

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.