Solved

Remove PHP comments using Dreamweaver Regexes

Posted on 2009-05-08
10
1,277 Views
Last Modified: 2012-06-22
Hello,

I need to remove all of the comments in a php file that is over 4000 lines long.

The comments consist of both types /**/ and //

I have a regular expression for the /**/ part :- [code sec below]

How can i remove the // comments from the document using Dreamweavers (unix like) regexes?
/\*[\S\s]+?(?=\*/)\*/

Open in new window

0
Comment
Question by:wilson1000
  • 6
  • 4
10 Comments
 
LVL 27

Accepted Solution

by:
ddrudik earned 500 total points
ID: 24339596
Tested with DW CS4:
(?:^|\n)[^\S\r\n]*(?://[^\r\n]*|/\*(?:(?!\*/)[\S\s])*\*/[^\r\n]*)

Open in new window

0
 
LVL 4

Author Comment

by:wilson1000
ID: 24355088
Unfortunately, this crashes Dreamweaver CS3 - I haven't moved over to CS4 as yet because of the transition with plugins.

When the regexe runs it clears only some of the comments but looks as though it gets stuck.

What would cause this?

0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24355245
Not sure, if you can attach a .txt file example of what crashes CS3 I can try it with CS4.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Author Comment

by:wilson1000
ID: 24355585
Thank you ddrudik, file attached...

php-comments.txt
0
 
LVL 4

Author Comment

by:wilson1000
ID: 24355615
Sorry, this isn't enough code please bear with me a second...
0
 
LVL 4

Author Comment

by:wilson1000
ID: 24356083
... try this one ...

php-comments.txt
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24356118
267 replacements made in CS4.
php-comments.txt
0
 
LVL 4

Author Comment

by:wilson1000
ID: 24356682
Cool, so it works in CS4.

How do you find CS4 in comparison to CS3?
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24357131
I moved from MX2004 to CS4 so I don't have experience with CS3.  I haven't found anything with CS4 that I dislike but I code more than I design.

Thanks for the question and the points.
0
 
LVL 4

Author Comment

by:wilson1000
ID: 24357207
No trouble, same here from the coding angle - much cleaner & quicker.

Take care
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question