1

The following regex works on PCRE, & Python but not on Javascript.

/(?s)\/\*\*\*\/\s\(function\(module,\sexports\)\s\{(.*?)\}\)\,/g

It seems that Javascript does not recognize (?s). Is there a Javascript equivalent for this?

https://regex101.com/r/IjWLqp/1

1

1 Answer 1

1

(?s) enables the s regex flag for the remainder of the pattern, which means that the . matches any character at all, instead of its default behavior of matching any character except newline. However, JavaScript, besides not supporting (?flags), doesn't have an s flag to begin with. Instead, we can replace the . pattern with [^] (the negation of an empty character class), which has the same effect of matching any character at all.

The overall pattern is then

/\/\*\*\*\/\s\(function\(module,\sexports\)\s\{([^]*?)\}\)\,/g
Sign up to request clarification or add additional context in comments.

1 Comment

Makes a a lot of sense. Thanks for the excellent explanation. Is there a doc which describes what js can do vs others?

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.