in reply to Re^3: Regular Expression Doubt
in thread Regular Expression Doubt

dammit
my $output = ""; while ($text =~ m/((<maths>.*?<\/maths>)|&plus;|.)/gs) { if ($2) { $output .= $1; } else { my $segment = $1; $segment =~ s/&plus;/&thinsp;&plus;&thinsp;/g; $output .= $segment; } } print $output . "\n";

Replies are listed 'Best First'.
Re^5: Regular Expression Doubt
by Anonymous Monk on Apr 06, 2005 at 08:41 UTC
    Eh, if you go that way, it could be made much more efficient. No need for the s/// - you're matching any &plus; already:
    my $output = ""; while ($text =~ m{\G(?:&plus;|(<maths>.*?<\/maths>|[^&<]+|.))}gs) { $output .= $1 || "&thinsp;&plus;&thinsp;"; } print $output, "\n";