1

Is there a regex for comments that look like this:

/**
 * -string- (possible line) 
-possibly more lines like the above one-
 */

For example:

/**
 * The Boring class implements this and that
 * and also...
 * does this and that
 */
1
  • Which language are you using? Regex is not the same in every langauge. Commented Jun 6, 2012 at 21:19

1 Answer 1

5

A simple /\*\*.*?\*/ with a dotall (dot matches all) flag should do the trick. Although it may require different escaping or possible delimiters depending on which flavour of regex engine you're using.

If you don't have dotall in your engine try something like:

/\*\*[\s\S]*?\*/
Sign up to request clarification or add additional context in comments.

6 Comments

May also need to be explictly set as "multiline" if the language supports it
Might need to explicitly exclude the trailing */ with \/\*\*^(\*\/)*?\*\/, also you're missing an escape before the last slash.
The first one doesn't work (with multiline), the second one works
@Hans I don't mean to escape any /. That's only necessary if / is picked as a delimiter and the engine requires delimiters, otherwise / has no special meaning. Since the question didn't specify I had to make some assumptions in my answer :)
@cookya Glad you got one to work :) [\s\S] means any character that is either whitespace or not whitespace (which is a long-winded way of saying any character).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.