tfE
tfE

Reputation: 190

removing php comments with replace tool using regex in phpstorm

How do I remove multiline comments from php files with regex? I tried "/\*(.*\n)*\*/" but it fails. All it does is starts with "/*" and stops at the last occurrence of "*/".

Upvotes: 5

Views: 2180

Answers (1)

tfE
tfE

Reputation: 190

Thanks to the tenub comment.

The final solution for all php comments looks like this:

/\*[\s\S]*?\*/|(?<!http:)//.*

Where

1) /\*[\s\S]*?\*/ for /*comments*/

2) (?<!http:)//.* for single line //comment escaping urls starting with http:// (it would be better to prevent the ones preceded by " or ' from showing but I'm good for now)

Oh and tenub if you post a corrected answer instead of the comment. I'll accept it. Cos you helped ty)

Upvotes: 5

Related Questions