in reply to Regex to match between [ref] and [/ref]

Untested, so may contain typos:
m{\Q[ref]\E(?:(?!\Q[/ref]\E).)*\Q[/ref]\E} # Simple m{\Q[ref]\E[^[]*(?:\[(?!\Q/ref]\E)[^[]*)*\Q[/ref]\E} # Some unrolling

Replies are listed 'Best First'.
Re^2: Regex to match between [ref] and [/ref]
by ultranerds (Hermit) on Jul 17, 2009 at 10:37 UTC
    Hi,
    Thanks - tried those 2, but both give no content (but they do seem to produce 2 matches - just without any values =))
    while ($test =~ m%\Q[ref]\E(?:(?!\Q[/ref]\E).)*\Q[/ref]\E%gix) { print "FOO, $1, $2 and $3 \n"; }

    ..and:
    while ($test =~ m%\Q[ref]\E[^[]*(?:\[(?!\Q/ref]\E)[^[]*)*\Q[/ref]\E +%gix) { print "FOO, $1, $2 and $3 \n"; }
    TIA

    Andy
      Not very surprising, is it? Regexes that do not contain capturing parenthesis don't set $1.