Without punctuation and string delimiters, it's very difficult to know exactly what you're asking. The guidelines in "How do I post a question effectively?" will help you post a better question.
Regex substitution is performed with s///. You should probably read "perlrequick - Perl regular expressions quick start" and "perlretut - Perl regular expressions tutorial" to get a basic understanding of Perl's regular expressions before doing anything else.
It sounds like you probably want a lookup table and a regex using alternation. Here's a very simplistic example of the technique:
#!/usr/bin/env perl -l use strict; use warnings; my %lookup = ('500' => '000', '0 988' => '000', '0 1210' => '1000'); my $re = '(' . join('|' => keys %lookup) . ')'; my $string = 'www "999" xxx "0 1210" yyy "500" zzz "0 988"'; print $string; $string =~ s/$re/$lookup{$1}/g; print $string;
Output:
www "999" xxx "0 1210" yyy "500" zzz "0 988" www "999" xxx "1000" yyy "000" zzz "000"
Depending on the context of the strings to be replaced, the pattern may need to be a lot more complex than that shown. For instance, given '500 988', do you want to replace 500' and ignore ' 988' or ignore '50' and replace '0 988'. Reading the documentation I linked to will help you understand these issues and how to deal with them. And, of course, assuming '0 988' is a string to be replaced is just a guess on my part (as I alluded to in the opening paragraph).
-- Ken
In reply to Re: String regex replacement
by kcott
in thread String regex replacement
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |