Nobody's mentioned that '^M' isn't the way you express a newline. It looks like you're trying to remove all those ^Ms you see in your files. Those are not really "caret character" plus "letter m character" (which is what you describe), but a special character called a carriage return that just appear that way in editors.

People who see this problem are likely using some form of Unix. You likely have a program called dos2unix on your system. Use that on your files.

Barring that, here's a perl one-liner from the Unix prompt that will do the same thing.

% perl -pi~ -e 's/\r//' *.txt

If you really need to do this in your own code, the bit between the single quotes is useful to you.

Update: From above replies, it looks like you do know the difference between '^M' and '\r', but I hope the information is still useful for yourself or others.

--
[ e d @ h a l l e y . c c ]


In reply to Re: substituting constants within regex? by halley
in thread substituting constants within regex? by Anonymous Monk

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.