Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: urgent perl regexp help needed

by Sec (Monk)
on Jul 20, 2005 at 15:13 UTC ( [id://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 (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://476520]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found