RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
/\*[\d\D]*?\*/
Description
If you need to extract or remove any /* */ sytle comments from any Java, JavaScript, C, C++, CSS, etc code you have this regular expression can help.
Matches
/* my comment */ | /* my multiline comment */ | /* my nested comment */
Non-Matches
*/ anything here /* | anything between 2 seperate comments | \* *\
Author Rating: The rating for this expression. Chris Craft
Source http://www.cjcraft.com/
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: afdaf
Name: afdasfd
Date: 1/9/2005 1:09:29 AM
Comment:
/* this is a comment*/


Title: matching comments correctly
Name: Trevor Miranda
Date: 10/28/2003 5:05:45 AM
Comment:
A correct solution that will handle comments inside quoted string is available in perlfaq6. Try this link: http://www.perldoc.com/perl5.6.1/pod/perlfaq6.html#How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file-


Title: Doesn't properly match nested comments
Name: Jan Willem
Date: 8/19/2003 10:44:48 AM
Comment:
/* outer comment */ inner comment */ This should not match since the amount of /* 's is lower than the amount of */ 's


Title: Problem with Strings
Name: Markus
Date: 5/21/2003 5:34:55 AM
Comment:
You will run into Problems, if you actually use this RE on a Code like this: (JAVA) text := " /* "; Command; /* COMMENT */ This RE will include everything starting from the first /*


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials