Reading the section regular expressions in EmacsWiki appears this:
You can use a tool to construct regexps. For example, you can use ‘rx’ like this:
(rx (or (and "\*" (*? anything) "*/") (and "//" (*? anything) eol)))
To produce this regexp (which matches C-style multiline and single line comments):
\\*\\(?:.\\|\n\\)*?\\*/\\|//\\(?:.\\|\n\\)*?$
I get the or
will match either C-style multiline or C/C++ single line comments.
But I do not get the and
parts.
I am not sure how
anything
works and am assuming that will match any char.
It might be something equivalent to.*
. Is it?If I got it right,
*?
is the non-greedy variant of*
operation.
Which really confuses me... The smallest possible match foranything
?Why the C-style multi-line opening is shown as "\*"? I suspect it is a typo on EmacsWiki and it should be "/*".
rx
under(info "(elisp) Rx Notation")
..
matches any char except newline. So.*
matches zero or more non-newline chars..\\|\n
matches any char (including newline).