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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:12:52+00:00 2026-05-26T12:12:52+00:00

The question is: How to do this using only (and a single) regex? Is

  • 0

The question is: How to do this using only (and a single) regex? Is it possible?

Explanation: I have an array like this:

array
(
   [0] => 'code1-{1,5}{a,c}',
   [1] => 'code2-{3,6}{s,q}'
)

and what I want to do is to get, using a regex, all the values grouped like:

code1
1,5
a,c

I know that I can get all the data inside the {...} using this regex:

'/\{([^\}]*)\}/i'

Besides I know that I can get the string before the dash using this one

/(.*?)\-/i

What I don’t know is if it’s possible to merge this two regex. Infact, if I have this regex

'/(.*?)\-\{([^\}]*)\}/i'

I can’t get all the data I need. I also know that I can do something like this:

'/(.*?)\-\{([^\}]*)\}\{([^\}]*)\}/i'

but if the format of the input will change to say 10 {…} groups, it’s no so elegant to have 10 group of the form \{([^\}]*)\} and it’s not the point of my question.

Here are the code that I’m trying:

First regex('/\{([^\}]*)\}/i'): http://ideone.com/mN3T2

Merged regex('/(.*?)\-\{([^\}]*)\}/i'): http://ideone.com/gMdOa

  • 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-26T12:12:53+00:00Added an answer on May 26, 2026 at 12:12 pm

    Update: After OP’s edit

    I don’t believe you can merge those two regular expressions and still retain the ability to loop through the matches of the form {1,5}. I think it is better to use two separate regular expressions for this purpose, one to capture coden and another to iterate over matches of text between {}.

    One way to do this is to split over - like this

    $result = preg_split('/-/m', 'code1-{1,5}{a,c}');

    and then you get code1 as the first entry and
    {1,5}{a,c} as the second entry. Now apply your regex

    \{([^\}]*)\} over the second entry and iterate over the matches.

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

Sidebar

Related Questions

I asked this question earlier: mod_rewrite: match only if no previous rules have matched?
This is kind of a 'double' question that might have a single answer. I'm
Firstly, I want to restrict this question to web development only. So this is
Using this question as the base is there an alogrithm or coding example to
ADDED: This question is now, I believe, subsumed by this one: Using GNU Screen
In relation to this question on Using OpenGL extensions , what's the purpose of
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
Yesterday I posted this question regarding using lambdas inside of a Join() method to
I bumped into an additional question that I needed in regards to this: Using
This question is about using getter methods of a singleton object in worker threads.

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.