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
    Thanks - that never gets any values though :/
    my $post_message = $DB->table('Post')->select( ['post_message'], { p +ost_id => $_[0] } )->fetchrow; print TESTOUT qq|testing the output of post_message - $post_message +\n\n |; $post_message =~ s{\[\[([^]]+)\]\]}{ # process($1) print TESTOUT qq|FOO: "$1"|; }esg
    TIA Andy

      It gets replaced with the result of the expression. In this case, it gets replaced with 1, the result of print. Remove print TESTOUT