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.

- 202,337
- 40
- 393
- 406
-
2Good answer, would just add see here: http://download.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html – Steve Jun 22 '11 at 13:59
-
16A sneaky gotcha is that `.*` does *not* match new-line character (`'\n'`). See [this question](http://stackoverflow.com/questions/3651725/match-multiline-text-using-regular-expression) for more info on that topic. – Captain Man Aug 11 '15 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
.

- 27,335
- 5
- 52
- 79
-
-
10@linqu, `.` will sometimes not match `\n` (newline), depending on the multiline option, but `[\s\S]` will match any character. – agent-j Mar 05 '14 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

- 90,351
- 20
- 107
- 135
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 .
.

- 7,052
- 2
- 29
- 39
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.

- 239,200
- 50
- 490
- 574

- 1,950
- 1
- 16
- 28