in reply to Constructing a list of regexes
use strict; sub make_regex_list{ my @regexes; foreach my $strings (@_) { my($regex_string,$options)=@$strings; push @regexes,qr/(?$options)$regex_string/; } return @regexes; } my $string = "Jack Jack John JACK john"; # in real code this array would be constructed # from a file my @reStrings=(["jack","ig"],["john","i"]); my @REGEXES=make_regex_list(@reStrings); foreach my $regex (@REGEXES) { #check to see if the regex contains the g modifier in it; if ( $regex =~ /^\(\?-xism:\(\?[^g|\)]g.*?\)/ ) { $string=~s/$regex/name/g; } else #no g modifier in $regex { $string=~s/$regex/name/; } } print $string."\n"; __END__ E:\>237215.pl name name name name john
-enlil
|
|---|