in reply to Arguments to substitution question
You are failing to escape the parenthesis, so they are carrying their structural meaning rather than being treated as plain old anchor text in the pattern. Simalarly the + is a quantifier; it carries meaning as well. Try this:
s/& \(0\+255\)//;
Here's an example:
my $have = q{clrf __pbssCOMRAM& (0+255),c}; my $want = q{clrf __pbssCOMRAM,c}; $have =~ s/& \(0\+255\)//; print "$have\n$want\n"; print "They ", ($have eq $want ? '' : "don't "), "match\n";
If you want to figure out how to use regular expressions with Perl, perlretut and perlrequick are good starting points.
Another strategy is to tell Perl that what follows should have any "special characters" escaped automatically:
s/\Q& (0+255)//;
The \Q feature is documented in quotemeta.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Arguments to substitution question
by rich.wilder (Initiate) on Sep 12, 2015 at 03:32 UTC | |
by ramachandrajr (Novice) on Sep 12, 2015 at 10:48 UTC | |
by ramachandrajr (Novice) on Sep 12, 2015 at 10:57 UTC |