in reply to Re: Regex: continue from previous match
in thread Regex: continue from previous match
PREMATCH is giving me the whole beginning of the string to the next match, not the part between the last search result and the next.
I guess to find the stuff between matches as well as the matches, I need to put it explicitly within a capture too. A lazy match of anything first.use 5.10.1; use utf8; my $simples = qr{\*\*|//}; my $ps= qr/ (?<simple>$simples)(?<body>.*?)\k<simple> /x; my @results; my $line= q[You can make things **bold** or //italic// or **//both//** + or //**both**//.]; say "Original: [$line]"; while ($line =~ /$ps/pgc) { say "pos is " . pos($line); say "PREMATCH: (${^PREMATCH})" unless length(${^PREMATCH}) == 0; say "SIMPLE: ($+{simple}) ($+{body})"; }
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Regex: continue from previous match
by moritz (Cardinal) on Apr 23, 2011 at 08:39 UTC |