Solved

Remove PHP comments using Dreamweaver Regexes

Posted on 2009-05-08
10
1,267 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now