Solved

Remove PHP comments using Dreamweaver Regexes

Posted on 2009-05-08
10
1,275 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP regex for to add zero to before or after included number. 6 95
Powershell regex followup 13 75
regex to extract ip:john 17 73
Need help decoding the following expressions 1 39
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…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
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…

809 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