M-x replace-regexp, I found that both
([[:digit:]]+) will match
(123), and not one without parentheses, But the first will replace
123 and the second
(123). I wonder why the difference?
In emacs regular expressions (unlike most regexp engines),
\) are group delimiters, while
) match litteral brackets.
\([[:digit:]]+\) matches one digit or more, that is here
123, and makes it a group. That means that for example,
\([[:digit:]]+\)? would match either
123 or some empty string, and that you can use
\1 (assuming it is your only group) for
123 in the replacement text.
On the other hand,
([[:digit:]]+) matches an opening bracket, one digit or more, then a closing bracket, so it will match