What is the regex expression to identify comments (i.e. all characters between /* and */ , including these comment markers themselves, and across multiple lines)?
So for example to pickup:
/* asdf asdf
asdf asdfasdfasdfasd
asdfasdf
*/
What is the regex expression to identify comments (i.e. all characters between /* and */ , including these comment markers themselves, and across multiple lines)?
So for example to pickup:
/* asdf asdf
asdf asdfasdfasdfasd
asdfasdf
*/
(?:/\*(?:(?:[^*]|\*(?!/))*)\*/)
This was originally part of a MySQL parser, designed to strip comments without removing them from strings:
("(?:(?:(?:\\.)|[^"\\\r\n])*)"|'(?:(?:(?:\\.)|[^'\\\r\n])*)'|`(?:(?:(?:\\.)|[^`\\\r\n])*)`)|((?:-- .*)|(?:#.*)|(?:/\*(?:(?:[^*]|\*(?!/))*)\*/))
That gets replaced with capture group 1 to put the strings back.
This is a very difficult problem to solve with a regex (since it is very hard to account for all the edge cases). If this is a programming language that you are parsing I would highly suggest that you use a parser built to parse that language.
It is not that simple e.g.:
/* multiline comment
f("end marker inside literal string */");
*/
See How do I use a regular expression to strip C style comments from a file?.