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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:17:33+00:00 2026-06-12T10:17:33+00:00

I have a handy-dandy regex provided from a previous SO question : $regex =

  • 0

I have a handy-dandy regex provided from a previous SO question:

$regex = qr/
    (sp\s+              #start with 'sp'        
    \{                  #opening brace
      (                 #save to $2
         (?:            #either
            \{ (?-1) \} #more braces and recurse
            |           #or
            [^{}]++     #non-brace characters
         )*             #0 or more times
      )                 #end $2
    \}                  #ending brace
    )                   #end $1
    /x;

I use it to extract textual structures from a file which are of the form sp {}, with possible further nesting of the curly braces. It correctly saves the following text in $1:

sp {foo {bar} baz}

But I’ve run into a problem: quoting. In the text I have, vertical bars can be used to quote:

sp {foo |}}}}bar}}}{{|}

That entire thing is one structure, but the current regex I have will only match sp {foo |}. The matter is further complicated because a vertical bar can be escaped within a quote
using a backslash:

sp {foo |}\|bar|}

should also match. Does anyone have any ideas on how to soup-up this regex to handle quotes and quote escaping?

  • 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-12T10:17:34+00:00Added an answer on June 12, 2026 at 10:17 am

    Replace

    [^{}]
    

    with

    (?: [^|{}]++
    |   \| (?: [^\\|]++ | \\. )*+ \|
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From my previous question I understood that I have to change my SVN repository
Does anyone have a handy powershell script that gets a set of files from
I've been looking for a simple regex for URLs, does anybody have one handy
I have written the odd handy function while I've been doing python. (A few
I have generated a C# SharePoint Sequential Workflow project using the very handy STSDEV
An idle question on language design, see Does C# have a right hand if
In Ruby, objects have a handy method called method_missing which allows one to handle
One trick I have found very handy in rails application programming is that class_eval
When I use svn up , it would be handy to have a list
Actually, I have a design question here. Its very simple but the point is:

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.