Solved

Remove PHP comments using Dreamweaver Regexes

Posted on 2009-05-08
10
1,287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
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…

691 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