in reply to Unexpected results from a regex replacement
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.
......### 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 >
<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 > --->
|
|---|