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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find C++ Comments
Expression
//.*|/\*[\s\S]*?\*/
Description
Matches single line or multi-line comments.
Matches
// Comment here | /// Comment here | /* Cmment Here */ | /**** Comment Here ****/
Non-Matches
/ * Comment Here */ | /* Comment here * /
Author Rating: The rating for this expression. Bill Krahmer
Source Bill Krahmer
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: Test in Javascritp
Name: PacoDw
Date: 4/15/2018 4:46:23 PM
Comment:
It's the best, I had to change it a bit to use in javascript but it is the same. Here is the change: const regex = new RegExp("//.*|/\\*[\\s\\S]*?\\*/","g");


Title: test
Name: foooo
Date: 10/25/2012 12:08:04 AM
Comment:
// //fffdasf //


Title: test
Name: foooo
Date: 10/25/2012 12:07:48 AM
Comment:
// //fffdasf //


Title: fast and furious regex dude!
Name: sombriks
Date: 9/27/2011 8:48:15 AM
Comment:
the best part is the performance with java String.matches for the cases when the expression must return false. Other versions always threw me in some kind of endless loop, but not this one, it's like a thunderbolt!


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