Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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);


Comment on Re: urgent perl regexp help needed
Download Code
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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://476520]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-08-31 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls