Those spurious comment tags may be the result of some other part of your code, perhaps a loop. If you wanted to, you could comment out all the cfmail tags in your file with a single RegEx if you turn on the 's' flag at the end of your RegEx.

The RegEx in the following sample code is a tad longer, but it enables you to comment out all the cfmail tags, even those that are not 'neatly typed in' but still valid CFML. It also does all the replacements without using a 'loop' because of the 's' flag that we tack on to the end.

...
before ...
...
### begin_: file metadata ### desc : comment out cfmail tags in a coldfusion file ### begin_: init perl use strict; use warnings; my $sTest = join '',<DATA>; ### ### begin_: do the replacement $sTest =~ s{(<\s*cfmail[^>]*>.*?\s*/\s*cfmail\s*>)} {<!---\n$1\n--->}gs; print $sTest; __DATA__ <cfparam name="foo" value="fee" /> <cfmail to="#to_address#"> yadda yadda yadda </cfmail> <cfoutput> the following cfmail tag is messy, but still valid cold-fusion CFML </cfoutput> < cfmail to="#to_address#" > yadda yadda yadda </ cfmail >
...
after ...
...
<cfparam name="foo" value="fee" /> <!--- <cfmail to="#to_address#"> yadda yadda yadda </cfmail> ---> <cfoutput> the following cfmail tag is messy, but still valid cold-fusion </cfoutput> <!--- < cfmail to="#to_address#" > yadda yadda yadda </ cfmail > --->

In reply to Re: Unexpected results from a regex replacement by dimar
in thread Unexpected results from a regex replacement by yacoubean

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.