203

I'm wondering is there a symbol for any number (including zero) of any characters

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Skizit
  • 43,506
  • 91
  • 209
  • 269

5 Answers5

320
.*

. is any char, * means repeated zero or more times.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • 2
    Good 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
  • 16
    A 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
50

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
  • 27,335
  • 5
  • 52
  • 79
29

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
  • 90,351
  • 20
  • 107
  • 135
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
  • 7,052
  • 2
  • 29
  • 39
-9

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.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Loduwijk
  • 1,950
  • 1
  • 16
  • 28