(\\d+|)
vs (\\d+)?
[\\w\\W]
vs [\\d\\D]
vs .
Is there any difference between t
You didn't say which language you're using, so I'm going to assume Perl.
(\d+|)
is equivalent to (\d*)
. It matches a sequence of 0 or more digits and captures the result into $1
. (\d)?
matches 0 or 1 digit. If it matches a digit, it puts it in $1
; otherwise $1
will be undef
(you could rewrite it as (?:(\d)|)
if you want to eliminate the ?
).
[\w\W]
and [\d\D]
are equivalent, matching any character. .
is equivalent to [^\n]
by default (matching any character but newline). If you really want to match any character, you should use .
and specify the /s
flag, which makes .
match any character.