任何字符,包括换行符 - Java Regex [英] Any character including newline - Java Regex
问题描述
我认为它可能是[。\ n] +但这似乎不起作用?
I thought it may be [.\n]+ but that doesn't seem to work?
推荐答案
dot不能在字符类中使用。
The dot cannot be used inside character classes.
请参阅选项 Pattern.DOTALL 。
Pattern.DOTALL
启用dotall模式。在dotall模式下,表达式。
匹配任何字符,包括行终止符。默认情况下,此表达式与行终止符不匹配。也可以通过嵌入式标志表达式(?s)
启用Dotall模式。 (s是单行模式的助记符,这是在Perl中调用的。)
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.)
如果你需要它只是正则表达式的一部分,你使用例如 [\\\\ S]
。
If you need it on just a portion of the regular expression, you use e.g. [\s\S]
.
这篇关于任何字符,包括换行符 - Java Regex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!