in reply to Regex help

So you've got multiple possible strings, and some of them might be substrings of others of them? If you combine them into one alternation, longest first, you should be ok:
my $super_regex = join '|', sort {length $b <=> length $a} map quoteme +ta($_), @list; $var_val =~ s/($super_regex)/$prefix$1$suffix/g;
Regexp::Optimizer might be of use if @list is long.

Update: added quotemeta as per ikegami's note.


Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Regex help
by ikegami (Patriarch) on Jun 02, 2005 at 18:18 UTC
Re^2: Regex help
by snacktime (Sexton) on Jun 02, 2005 at 17:59 UTC
    Ah that's exactly what I was looking for. Sorry for not explaining the issue correctly in my first post. Some of the strings being substrings of others was the real issue as you guessed.