177

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

Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476
Skizit
  • 40,756
  • 89
  • 203
  • 267

5 Answers5

287
.*

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

Mat
  • 195,986
  • 40
  • 382
  • 396
  • 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
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
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
-8

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
  • 230,875
  • 49
  • 477
  • 553
Loduwijk
  • 1,882
  • 1
  • 16
  • 26