• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Excluding CF and Js Commenting tags

Explorer ,
Apr 19, 2014 Apr 19, 2014

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.

Views

479

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Apr 22, 2014 Apr 22, 2014

The below code worked for me.

For CF Comments : <cfset filecontent = rereplace(filecontent, "<!---.*?--->", "", "all")>

For .js comments:   <cfset filecontent = rereplace(filecontent, "\/\*.*?\*\/", "", "all")>

Votes

Translate

Translate
Participant ,
Apr 21, 2014 Apr 21, 2014

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.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2014 Apr 22, 2014

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 22, 2014 Apr 22, 2014

Copy link to clipboard

Copied

LATEST

The below code worked for me.

For CF Comments : <cfset filecontent = rereplace(filecontent, "<!---.*?--->", "", "all")>

For .js comments:   <cfset filecontent = rereplace(filecontent, "\/\*.*?\*\/", "", "all")>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation