Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: urgent perl regexp help needed

by Sec (Monk)
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 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.


    Edited by Chady -- added formatting

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://476520]
and a soft breeze sighs...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2017-11-19 18:47 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (282 votes). Check out past polls.