Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: urgent perl regexp help needed

by Sec (Scribe)
on Jul 20, 2005 at 15:13 UTC ( #476520=note: print w/replies, xml ) Need Help??


in reply to urgent perl regexp help needed

With the help of "man perlre" it is easy. Just steal the "match parenthesized group" snippet, and use it as an alternative in the match you want.
$abc = "abc,xyz,{1,2,3,4},18-90-89,{{1,2},{5,6,7,8}},yts"; $par=qr! \{ (?: [^{}]+ | (??{ $par }) )+ \} !x; @a= $abc=~ /([^{,]+|$par)/g; print join("\n",@a);

Replies are listed 'Best First'.
Re^2: urgent perl regexp help needed
by ikegami (Pope) on Jul 20, 2005 at 15:28 UTC

    I'd use * instead of +, since he didn't say empty fields were not allowed. And what if the bracket are is not the first character? Fixed and documented:

    $_ = "abc,xyz,{1,2,3,4},18-90-89,{{1,2},{5,6,7,8}},yts"; # Create a regexp to match nested brackets. my $par; # Can't combine this with next line. $par = qr/ \{ # Opening bracket. (?: # Match zero or more [^{}]+ # non-brackets | # or (??{ $par }) # bracketed content. )* \} # Closing bracket. /x; # Extract fields from the line. my @elems = / \G # Start where last match left off. ( # Capture (return) (?: # zero or more [^{,]+ # non-brackets, non-commas | # or $par # bracketed content. )* ) (?: , | $) # Match comma or end of line. /xg; print(join("\n", @elems));

      thanks a lot!...that was really useful and informative

      Edited by Chady -- added formatting

Re^2: urgent perl regexp help needed
by karthikpa (Novice) on Jul 20, 2005 at 15:27 UTC

    Thanks a lot Sec...it worked. Could you please explain to me what exactly you are doing here...I tried reading man pages but there is not much of detail there.

    the help is really appreciated.

    Thanks
    Karthik

    Edited by Chady -- added formatting

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://476520]
help
Chatterbox?
[Lady_Aleena]: Hello Discipulus, Corion, choroba, and marioroy...
[Corion]: Hi Lady_Aleena!
[Lady_Aleena]: marioroy, are you also writing a Meditation for this?
choroba o/
Discipulus adds tozzetti alle mandorle to the platter on the sideboard.
Lady_Aleena was checking #cbstream and saw the big announcement.
[marioroy]: Tie::IxHash can be shared. Also similar modules. I cannot wait to post a solution sharing Tie::File and iterating among workers.
[marioroy]: Lady_Aleena Yes, will post something with all the new features. Parallel with few lines of code.
[marioroy]: Yes, will do for PM. I love PM.
Lady_Aleena ponders a meditation of her own, but it would be on a far far less important topic.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-05-26 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?