in reply to multiple-line match mucking with regex registers
You could do it this way: (Basically merging the two regexes so that only two sets of capture brackets appear.)
#! perl -slw use strict; my @lines = ( '111 MatchMe [This is why]', '222 I need to be dispatched to the same callback: For This Reason', ); for ( @lines ) { m/ ^(\d+) \s (?: (?-x:I need to be dispatched.*?: ) | (?-x:MatchMe \[) ) (.*?) \]? $ /x and print "'$1'$2'"; } __END__ C:\test>junk '111'This is why' '222'For This Reason'
Though you will have to decide whether the possibility of obtaining a false matche against lines like update: these
111 MatchMe [This is why 222 I need to be dispatched to the same callback: For This Reason]
is a problem for your application?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: multiple-line match mucking with regex registers
by GrandFather (Saint) on Jul 11, 2006 at 17:59 UTC | |
|
Re^2: multiple-line match mucking with regex registers
by Voronich (Hermit) on Jul 11, 2006 at 14:28 UTC |