in reply to Regex keeps looping on itself :/

$str =~ m/.../g in scalar context keeps track of its current position via pos($str), and $str =~ s/.../.../g resets pos($str).

You could something along these lines instead:

$post_message =~ s{\[\[([^]]+)\]\]}{process_match($1)}ge; sub process_match { my $tmp = shift; if ($DB->table('Articles')->count( { article_title => $tmp } ) > 0) + { # return modified text here } else { return $tmp; # unmodified text } }

Replies are listed 'Best First'.
Re^2: Regex keeps looping on itself :/
by ultranerds (Hermit) on Jun 18, 2009 at 14:41 UTC
    Hi,

    The solution works perfectly - thank you very much :) Will have to remember that trick for another time.

    Cheers

    Andy