Regular expression for using * with /* and */ to delete comments

Find, replace, find in files, replace in files, regular expressions

Regular expression for using * with /* and */ to delete comments

Postby englocon » Wed May 11, 2011 2:57 pm

Hello All,

Does anyone know what the regex in the replace function in UltraEdit 16.30 should be to delete comments from a file that start with /* and end with */? I tried "/***/" (without quotes) and it did not work.

Thanks
englocon
Newbie
 
Posts: 2
Joined: Wed May 11, 2011 2:53 pm

Re: Regular expression for using * with /* and */ to delete comments

Postby bulgrien » Wed May 11, 2011 9:15 pm

With a Perl regular expression, you can do it this way:

(?s)/\*.*\*/

\* matches an asterisk. Since * is a special character, the \ is needed to escape the special functionality and match the actual character.

.* matches everything in between. The . is a wildcard that matches any character. The * says to match as many characters as it can find. By default, the . wildcard doesn't match end-of-line characters and thus will only match characters within a single line.

(?s) is a special switch that tells the regex engine that the . wildcard character should also match end-of-line characters.
User avatar
bulgrien
Master
Master
 
Posts: 92
Joined: Fri Dec 11, 2009 1:02 am
Location: Pennsylvania, USA

Re: Regular expression for using * with /* and */ to delete comments

Postby englocon » Thu May 12, 2011 8:30 am

Thanks, bulgrien.
englocon
Newbie
 
Posts: 2
Joined: Wed May 11, 2011 2:53 pm


Return to Find/Replace/Regular Expressions