Copy link to clipboard
Copied
I am counting the number of lines on code in .cfm pages. But i want to exclude the lines between the CF and Javascript commenting tags while doing this.
I tried replacing the lines in between the commenting tags with empty string like the below one.
For CF commenting tags : <cfset filecontent=rereplacenocase(filecontent,"<![^<]*>","","all")>
For Js Commenting tags : <cfset filecontent=rereplacenocase(filecontent,"/*[^<]*/","","all")>
But mostly the above method does not exclude the codes. can anyone suggest any alternate method to achieve this.
The below code worked for me.
For CF Comments : <cfset filecontent = rereplace(filecontent, "<!---.*?--->", "", "all")>
For .js comments: <cfset filecontent = rereplace(filecontent, "\/\*.*?\*\/", "", "all")>
Copy link to clipboard
Copied
Did you mean:
For CF commenting tags : <cfset filecontent=rereplacenocase(filecontent,"<![^>]*>","","all")>
Javascript /* */ are trickier, since both * and / are valid symbols within comments. This should work:
<cfset filecontent = REReplace(filecontent, "/\*.*\*/", "", "ALL")>
Don't forget the "//" style Javascript comments, which you can probably match with something like:
<cfset filecontent = REReplace(filecontent, "//.*(\r\n|\n)", "", "ALL")>
(It is seldom a good idea to use .* in regular expressions--you often get more than you bargained for. But these examples are just for illustration.)
Copy link to clipboard
Copied
gokul1242 wrote:
I am counting the number of lines on code in .cfm pages. But i want to exclude the lines between the CF and Javascript commenting tags while doing this.
What do you need the number of lines of code for? You may not need to exclude the comments.
Comments, if well motivated, are an integral part of the code! In fact, in most software engineering and project management analyses, the required value of the number of Source Lines of Code (SLOC) actually includes comment lines!
Copy link to clipboard
Copied
The below code worked for me.
For CF Comments : <cfset filecontent = rereplace(filecontent, "<!---.*?--->", "", "all")>
For .js comments: <cfset filecontent = rereplace(filecontent, "\/\*.*?\*\/", "", "all")>