__[username]__[string]__
There can be multiple instances of [string] in a line, and I don't want to match [string] a second time once it's been rewritten.
Here is what I am doing now. I know there has got to be a better way, but this does work.
my $prefix = "__" . $self->{user} . "__"; my $suffix = "__"; my %hash; my $c =0; my @contexts = sort {length $b <=> length $a} @list; foreach my $context (@contexts) { if($var_val =~s/($context?)/\@\@$c\@\@/g) { $hash{$c} = "$prefix$1$suffix"; $c++; } } foreach my $key (keys %hash) { $var_val =~s/\@\@$key\@\@/$hash{$key}/g; }
In reply to Regex help by snacktime
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |