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


In reply to Re: Arguments to substitution question by davido
in thread Arguments to substitution question by rich.wilder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.