in reply to multiple-line match mucking with regex registers

Use an alternation (|) in a non-capture group to match the alternative bits:

use warnings; use strict; while (<DATA>) { chomp; next if ! /^(\d+) (?:MatchMe \[|I need to be dispatched.*\:\s)(.*? +)\]?$/; print "Line $1, reason: $2\n"; } __DATA__ 111 MatchMe [This is why] 222 I need to be dispatched to the same callback: For This Reason

Prints:

Line 111, reason: This is why Line 222, reason: For This Reason

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: multiple-line match mucking with regex registers
by Voronich (Hermit) on Jul 11, 2006 at 14:35 UTC
    Yep. That looks like the right answer.

    I was trying to do something similar, but had it factored wrong.

    w00t! Thanks =)