I'm wondering is there a symbol for any number (including zero) of any characters
Asked
Active
Viewed 2.6e+01k times
5 Answers
287
.*
. is any char, * means repeated zero or more times.
Mat
- 195,986
- 40
- 382
- 396
-
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
45
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.
agent-j
- 26,389
- 5
- 49
- 78
-
-
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
27
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
stema
- 85,585
- 19
- 101
- 125
6
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 ..
Miki
- 6,987
- 2
- 29
- 38