Symbol for any number of any characters in regex?

前端 未结 5 1262
南笙
南笙 2020-11-29 21:21

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

相关标签:
5条回答
  • 2020-11-29 21:42

    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.

    0 讨论(0)
  • 2020-11-29 21:43

    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.

    0 讨论(0)
  • 2020-11-29 22:01

    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 ..

    0 讨论(0)
  • 2020-11-29 22:06
    .*
    

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

    0 讨论(0)
  • 2020-11-29 22:07

    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

    0 讨论(0)
提交回复
热议问题