cwm9 has asked for the wisdom of the Perl Monks concerning the following question:
Here's what I've tried so far. This version is overly greedy -- it won't give up eating group 2 into group 1.left \1=left \2= right \1= \2=right rightabc \1= \2=rightabc leftright \1=left \2=right leftrightabc \1=left \2=rightabc
This version splits properly, but /2 is the same as /1 when there is no /2:s/(.*)(right)?/\1 <> \2/ echo "left"|perl -ne 'print if s/(.*)(right)?/\1 <> \2/' + left <> echo "right"|perl -ne 'print if s/(.*)(right)?/\1 <> \2/' + right <> echo "leftright"|perl -ne 'print if s/(.*)(right)?/\1 <> \2/' + leftright <>
s/(.*(?=right.*)|(.*))/\ echo "left"|perl -ne 'print if s/(.*(?=right.*)|(.*))/\1 <> \2/' + left <> left echo "right"|perl -ne 'print if s/(.*(?=right.*)|(.*))/\1 <> \2/' + <> right echo "leftright"|perl -ne 'print if s/(.*(?=right.*)|(.*))/\1 <> \2/' + left <> right
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capturing groups where the ending is optional
by tybalt89 (Monsignor) on Jan 15, 2018 at 00:03 UTC | |
|
Re: Capturing groups where the ending is optional
by ikegami (Patriarch) on Jan 14, 2018 at 23:42 UTC | |
by cwm9 (Initiate) on Jan 14, 2018 at 23:49 UTC | |
by AnomalousMonk (Archbishop) on Jan 15, 2018 at 03:48 UTC | |
|
Re: Capturing groups where the ending is optional
by AnomalousMonk (Archbishop) on Jan 15, 2018 at 00:30 UTC |