in reply to Re: urgent perl regexp help needed
in thread urgent perl regexp help needed
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));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: urgent perl regexp help needed
by karthikpa (Novice) on Jul 20, 2005 at 15:34 UTC |