[Anonymonk]: In common with previous respondents, I can't understand your problem (just what does "doesn't seem to work" mean?) with the code given in the OP: it does just what I understand you want done. Please see example below. (I use 'H' in place of '#' because my little command line editor thinks all #s are comments. Also, I give an alternate approach that I think might be more flexible. It could even be done without captures, but let's not get ahead of ourselves.)
>perl -wMstrict -le "my $text = 'foo size=\"10\">HHili1 bar size=\"10\">HHili22 baz'; print qq{'$text'}; ;; $text =~ s/size=\"10\">HHili(\d{1,2})/size=\"10\" text-anchor=\"end\" +>HHili$1/g; print qq{'$text'}; ;; my $toxt = 'fee size=\"10\">HHili1 fie size=\"10\">HHili22 foe'; print qq{'$toxt'}; ;; my $pre = qr{ size=\"10\" }xms; my $post = qr{ >HHili\d{1,2} }xms; my $insert = ' text-anchor=\"end\"'; $toxt =~ s{ ($pre) ($post) }{$1$insert$2}xmsg; print qq{'$toxt'}; " 'foo size="10">HHili1 bar size="10">HHili22 baz' 'foo size="10" text-anchor="end">HHili1 bar size="10" text-anchor="end +">HHili22 baz' 'fee size="10">HHili1 fie size="10">HHili22 foe' 'fee size="10" text-anchor="end">HHili1 fie size="10" text-anchor="end +">HHili22 foe'
In reply to Re: Simple regex help
by AnomalousMonk
in thread Simple regex help
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |