0
/** * SOMETHING BLABLABLA * Date: 3/16/14 * Time: 8:29 PM */ 

I want to match anything from /** to */

I can match /** to the first * with this:

/\*\*([^\*]*)\* 

But I don't know how to unmatch both last two letters.

5
  • javascript I think, I don't know it is something used in phpstorm / textmate / sublime when you use Find regex feature Commented Mar 16, 2014 at 14:50
  • 3
    What do you mean by unmatch? Commented Mar 16, 2014 at 14:51
  • 2
    This doesn't match any letters in your example? Do you mean characters? Can you show an example of what you want? Commented Mar 16, 2014 at 14:55
  • I wonder if perhaps you want a positive lookahead, e.g. (?=\*\/). I suspect not, though, given that you are already capturing the first /* Commented Mar 16, 2014 at 15:28
  • @jaycode Different "flavors" of regex have different syntaxes and different features in some areas. Are you using this in PHP, or in TextMate, or in Sublime? Commented Mar 16, 2014 at 15:30

2 Answers 2

3

You can use:

/(?:^\s*\/\*\*)(.*)(?:^\s*\*\/)/ms 

See it work

Or Debuggex version:

Regular expression visualization

Debuggex Demo

By 'unmatch' I think you mean have a group that is not included in the match group. You use a non capturing group that starts with (?:regex) to do that.

The full explanation is:

/(?:^\s*\/\*\*)(.*)(?:\s*\*\/)/ms (?:^\s*\/\*\*) Non-capturing group ^ assert position at start of a line \s* match any white space character [\r\n\t\f ] Quantifier: Between zero and unlimited times, as many times as possible, giving back as needed [greedy] \/ matches the character / literally \* matches the character * literally \* matches the character * literally 1st Capturing group (.*) .* matches any character Quantifier: Between zero and unlimited times, as many times as possible, giving back as needed [greedy] (?:\s*\*\/) Non-capturing group \s* match any white space character [\r\n\t\f ] Quantifier: Between zero and unlimited times, as many times as possible, giving back as needed [greedy] \* matches the character * literally \/ matches the character / literally m modifier: multi-line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string) s modifier: single line. Dot matches newline characters 

If you want to match:

/** * SOMETHING BLABLABLA * Date: 3/16/14 * Time: 8:29 PM*/ ^ comment terminator 

Just remove the anchor in the final non capturing group to be (?:\s*\*\/)


For Sublime, you need the flags ms to be set. Use:

(?ms)(?:^\s*\/\*\*)(.*)(?:^\s*\*\/) ^^^^ This part sets the flags for Boost regex engine... 
Sign up to request clarification or add additional context in comments.

2 Comments

This would also capture non JavaDoc blocks. It needs a second asterisk in the open marker: (?:^\s*\/\*\*)(.*)(?:^\s*\*\/)
Hi, it does not work when I use sublime text editor to find. Any idea why?
2

Try this, which requires dot-matches-all:

/\*\*.*?\*/ 

Alternatively, this captures all post-asterisk text on each line...sort of:

/\*\*(?:\s+\* ([^\r\n]+))+\s+\*/ 

Regular expression visualization

Debuggex Demo

Actually it only captures the last line, but it does seem closer.

3 Comments

That'll match the whole comment, which is what at first what I thought he wanted, but I don't think that's it...
almost the same thing I thought of, and I think it matches what the asker wanted, /(\/\*\*.*?\*\/)/m
I updated to something a little closer, I think, but I'm not clear on what is wanted.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.