in reply to Re^2: multi-line regexp
in thread multi-line regexp

maybe this helps:
perl -MYAPE::Regex::Explain -e 'print YAPE::Regex::Explain->new(qr/(aa +aaa(?:(?:(?!aaaaa).)*))/s)->explain'
The regular expression: (?s-imx:(aaaaa(?:(?:(?!aaaaa).)*))) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?s-imx: group, but do not capture (with . matching \n) (case-sensitive) (with ^ and $ matching normally) (matching whitespace and # normally): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- aaaaa 'aaaaa' ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- (?: group, but do not capture (0 or more times (matching the most amount possible)): ---------------------------------------------------------------------- (?! look ahead to see if there is not: ---------------------------------------------------------------------- aaaaa 'aaaaa' ---------------------------------------------------------------------- ) end of look-ahead ---------------------------------------------------------------------- . any character ---------------------------------------------------------------------- )* end of grouping ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

Replies are listed 'Best First'.
Re^4: multi-line regexp
by doctor_moron (Scribe) on Dec 23, 2005 at 11:23 UTC

    hi, do we need 'g' modifier here ?, i tried your pattern matching with this code :

    $str = "aaaaa\nbbbbb\nccccc\nddddd\naaaaa\nddddd\neeeee\n"; @a = $str =~ /(aaaaa(?:(?:(?!aaaaa).)*))/s; print "1 : $a[0]\n 2 : $a[1]\n";

    and this code only match "aaaaa bbbbb ccccc ddddd" ($a[0])

    and if we put g in pattern matching, i mean like this :

    $str = "aaaaa\nbbbbb\nccccc\nddddd\naaaaa\nddddd\neeeee\n"; @a = $str =~ /(aaaaa(?:(?:(?!aaaaa).)*))/gs; print "1 : $a[0]\n 2 : $a[1]\n";

    this will print out : "aaaaa bbbbb ccccc ddddd" and "aaaaa ddddd eeeee".

    thanks, zak