Is there a simple way to remove ColdFusion comments from a file?
Is there a quick way to remove all of the comments from a Coldfusion File? I have to work on a file that is mostly comments (especially comments of old non-functional code), and 开发者_运维百科I'd like to create a temporary version with no comments and functional code only.
I generally use Notepad++ to edit CFM files, but I also have ColdFusion Studio.
Any help is appreciated!
With CFML you can do it with a quick regex. This only works with CFML tag based comments, not script ones.
<cfset contents = fileRead(expandPath("./test2.cfm"))>
<cfset noComments = rereplace(contents, "<!---.*?--->", "", "all")>
<cfoutput>
#htmlCodeFormat(noComments)#
</cfoutput>
You need a multirow regex find/replace. Eclipse let's you do it with:(?s)<!---(.*?)--->
Alternately, you can..
Open http://gskinner.com/RegExr/
Enter <!---(.*\r)*---> into first box.
Press Replace Tab.
Copy/Paste your file's code into first text area.
Second text area will contain filtered code.
Works for CFML comments, you can modify regex to work for script comments.n
One way would be to create a cfm script to parse the entire .cfm file as a text file. (Using cffile or a java file method).
Then slip in a simple regex to remove anything between
There are several good regex examples that will remove particular tags from html that should work great for this.
Here's a regex I used to remove the first in some code that was wrapping itself around some XML I was rendering. It should be pretty close to what you need to remove all of the comments.
<\/?div[^>]*?>
Best of luck!
精彩评论