I'm wondering is there a symbol for any number (including zero) of any characters
5 Answers
.*
.
is any char, *
means repeated zero or more times.
-
2Good answer, would just add see here: download.oracle.com/javase/1.4.2/docs/api/java/util/regex/…– SteveJun 22, 2011 at 13:59
-
16A sneaky gotcha is that
.*
does not match new-line character ('\n'
). See this question for more info on that topic. Aug 11, 2015 at 19:32
You can use this regular expression (any whitespace or any non-whitespace) as many times as possible down to and including 0.
[\s\S]*
This expression will match as few as possible, but as many as necessary for the rest of the expression.
[\s\S]*?
For example, in this regex [\s\S]*?B
will match aB
in aBaaaaB
. But in this regex [\s\S]*B
will match aBaaaaB
in aBaaaaB
.
-
-
10@linqu,
.
will sometimes not match\n
(newline), depending on the multiline option, but[\s\S]
will match any character.– agent-jMar 5, 2014 at 20:08
Do you mean
.*
.
any character, except newline character, with dotall mode it includes also the newline characters
*
any amount of the preceding expression, including 0 times
I would use .*
. .
matches any character, *
signifies 0 or more occurrences. You might need a DOTALL switch to the regex to capture new lines with .
.
Yes, there is one, it's the asterisk: *
a* // looks for 0 or more instances of "a"
This should be covered in any Java regex tutorial or documentation that you look up.