0

I got this Regexp:

/(\/\*[\w\'\s\r\n\*]*\*\/)/g

I'd like to match single line comments, and multi lines comments with or without special characters.

So, this get matched:

/* hey ! */

/*
  ho
*/

But this doesn't (and I'd like this to get matched too) :

/* hey ! */

/*
  = ho
*/

/* line 3, ../../../app/assets/stylesheets/v3/reset.scss */

I tried many things, to no avail. Including replacing \w by \W, I'm out of ideas.

Live example: https://www.regex101.com/r/jV0dV1/2

2 Answers 2

1
\/\*[^\*\/]*\*\/

/* followed by any character(s) other than */, followed by */

Sign up to request clarification or add additional context in comments.

Comments

0

Use

/\*(?:(?!\*/).|\n)*\*/

regex101 demo.


Explanation:

/\*  literal /*
(?:
    (?! if the next characters aren't */
        \*/
    )
    .   consume the next character
|
    \n  also consume newlines, which the dot doesn't match
)*  ...as often as possible
\*/  literal */

Comments

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.