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

  • Home
  • SEARCH
  • 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 3279682
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:37:13+00:00 2026-05-17T19:37:13+00:00

I have a string that I want to parse using regex. It has the

  • 0

I have a string that I want to parse using regex. It has the follow format:

“random text [id value] more text [id value] other stuff”

I would like to find the pattern that will match [id value] the brackets included. Do I have to do anything special to return two matches instead of one match. My concern is that I will only return this match:

"[id value] more text [id value]"

using a pattern like this: \[((.|\n)*?)\]

I’m not very good at regex, so this may seem super trival. Does the regex parser move from left to right through the string?

I then have a follow up question that is a little more complicated. What if I have nested patterns:

"random text [id [id value]] more text [id value] other stuff"

I’d like to be able to capture [id [id value]] as a match and [id value] as a match. Is it possible to write one regex that will return both [id [id value]] and [id value]. In this situation I’d like to check for balanced brackets and then end on the last match, is that possible using regex?

  • 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-17T19:37:13+00:00Added an answer on May 17, 2026 at 7:37 pm

    Matching parentheses is the canonical example of a simple task that cannot be done using finite automata – and regular expressions are simply a language for describing finite automata. Matching parentheses requires a context-free grammar.

    Of course, modern regex libraries have capabilities that go well beyond basic regular expressions. So you might be able to manage something. I’d not hold out much luck, though.

    You’d probably be able to crank out a simple recursive-descent parser in less time than it would take you to figure out how to torture a regex into something that would mostly work.

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

Sidebar

Related Questions

I have a text file that is formatted like JSON, but in a print/view
When using optparse i want to get the whole string after an option, but
I have a string which represents a date, its given back from a DropDownList.
I have a file in JSON format with record for individual users. Some of
We have an Adobe Flex client talking to a .NET server using WebORB. Simplifying
I have a query in linqtosql that returns a LabelNumber: var q = from
I have several message queues that have specific messages on them. I've created classes
Even after years of programming, I'm ashamed to say that I've never really fully
So, for some strange reason I end up with a 100GB log file that
I've asked another related question to this here: casting dynamic to static problem I've

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.