in reply to Curious Regex

Another option, easier to read but slower than ikegami's solution:
sub stripCtrls { my $text = shift; #changed capture of $1 as per moritz $text =~ /(<\/Mil[^>]*>)([^\x9D]*)\x9D/; my $sStartTag = $1; my $sBetweenTags = $2; $sBetweenTags =~ s/[\x90\x8F]//g; return "$sStartTag$sBetweenTags\x9D"; }

which you can call like this stripCtrls($sTaggedText).

And if you don't need to preserve \x90 and \x8F in the start tag, maybe you might try the even simpler $text =~ s/[\x90\x8F]//g?

Best, beth

Update: put in sub so can be used as one liner

Replies are listed 'Best First'.
Re^2: Curious Regex
by HamNRye (Monk) on Feb 11, 2009 at 18:39 UTC

    Thanks... Yeah, unfortunately the "simpler" method doesn't work because I need to preserve the control chars outside of the tags.

    Here's what I have as a "two stage" deal... I was just hoping someone could help me figure out how to make this work as a one liner.

    if ($text =~ /<\/Mil[^>]*>(.*)\x9D/i) { my $string = $1; $string =~ s/[\x90\x8F]//g; $text =~ /(<\/Mil[^>]*>).*(\x9D)/$1$string$2/i; }
      Well, basically what you have done is the same idea as what I did except that you have three regex evaluations when only two are needed - you can extract the start tag at the same time as the middle stuff and then put it back together using simple interpolation - which is what I did. Its a bit faster that way, but you should stick with whatever version you will understand three weeks from now.

      As for the one liner - just put it all in a sub - either your version or mine or ikegami's which is even faster - and presto - a one liner. That is what subs are for.

      Best, beth