in reply to Regex keeps looping on itself :/
The following expression resets the position at which the next match will start:
$post_message =~ s/\Q[[$1]]/[[$article_id]]/sig;
You'd be better off reading from one var and storing the output in another.
while ($input =~ /\G(.*?)\[\[([^]]+)\]\]/sg) { my $link = $2; $output .= $1; $output .= process($link); }
Update: Oops, there's a bug in the above. It drops whatever's after the last link. It's actually easier to solve using a different technique.
$post_message =~ s{\[\[([^]]+)\]\]}{ process($1) }esg;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex keeps looping on itself :/
by ultranerds (Hermit) on Jun 17, 2009 at 15:43 UTC | |
by ikegami (Patriarch) on Jun 17, 2009 at 15:53 UTC |