in reply to Regex bafflement
Part of your problem may be with $text =~ s/$temp/$match/gsm;. The text in $temp may include regular expression meta characters. For example, in your sample data it includes (Attached). When you use this in the RE, the parentheses are not matched as characters - they provide grouping. As a result, the pattern doesn't match at all.
Whether your text is changed will depend on whether $text contains any regular expression meta characters or not. I take it from your description that in the case you described all but the last match did include meta characters.
One way to prevent the characters in $temp being interpreted as regular expression meta characters is to quote all the text as follows:
$text =~ s/\Q$temp\E/$match/gsm;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex bafflement
by rastoboy (Monk) on Oct 13, 2010 at 21:07 UTC |