Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Regular expressions: Extracting certain text from a line

by Wcool (Novice)
on Apr 07, 2014 at 11:45 UTC ( #1081393=note: print w/replies, xml ) Need Help??


in reply to Re: Regular expressions: Extracting certain text from a line
in thread Regular expressions: Extracting certain text from a line

I used the
tag as the pseudo HTML is creating havoc on square brackets. <code> Basically I want the most outer [ some chars] or { some chars } but no +t [] or {} 2 other examples: 1) a[] = [ this is a test { test2 } ] Should only match [ this is a test { test2 } ] 2) a[] = [ this is a [ test ] { test2 } ] Should return [ this is a [ test ] { test2 } ]

I simplified by looking only at square brackets but still no joy.

I thought of something like this:

\[ <- a square bracket .[^\/] <- followed by any character but not an end bracket + <- at least one character
I give up, I will just look for brackets and if it matches empty brackets I filter them out in the code

Replies are listed 'Best First'.
Re^3: Regular expressions: Extracting certain text from a line
by SimonPratt (Friar) on Apr 07, 2014 at 15:50 UTC

    Don't give up too quickly!

    (\[(?:[^\[\]]++|(?1))+\])

    That should get you started ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1081393]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2018-06-22 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (120 votes). Check out past polls.

    Notices?