Any character including newline - Java Regex

后端 未结 2 713
北荒
北荒 2020-11-27 05:01

I thought it may be [.\\n]+ but that doesn\'t seem to work?

相关标签:
2条回答
  • 2020-11-27 05:23

    The dot cannot be used inside character classes.

    See the option Pattern.DOTALL.

    Pattern.DOTALL Enables dotall mode. In dotall mode, the expression . matches any character, including a line terminator. By default this expression does not match line terminators. Dotall mode can also be enabled via the embedded flag expression (?s). (The s is a mnemonic for "single-line" mode, which is what this is called in Perl.)

    If you need it on just a portion of the regular expression, you use e.g. [\s\S].

    0 讨论(0)
  • 2020-11-27 05:44

    Edit: While my original answer is technically correct, as ThorSummoner pointed out, it can be done more efficiently like so

    [\s\S]

    as compared to (.|\n) or (.|\n|\r)

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