Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带分隔符的正则表达式_Java_Regex - Fatal编程技术网

Java 带分隔符的正则表达式

Java 带分隔符的正则表达式,java,regex,Java,Regex,我对regex命令有问题: text="blue: allocatable allocate assign" //it has delimiters (new lines) String patternblue = ".*blue.*"; boolean isMatchblue = Pattern.matches(patternblue, text.toString()); System.out.println(isMatchblue); 给出“假”,会发生什么 我查看了论坛中的其他帖子,但

我对regex命令有问题:

text="blue:
allocatable
allocate
assign" //it has delimiters (new lines)

String patternblue = ".*blue.*";
boolean isMatchblue = Pattern.matches(patternblue, text.toString());
System.out.println(isMatchblue);
给出“假”,会发生什么


我查看了论坛中的其他帖子,但我也没有发现它与。*?nor?s

对于此特定的
模式
,您需要使用
DOTALL
标志,否则
蓝色
之后的
*
将不匹配换行符

由于没有采用可选标志的
匹配
覆盖,您可能最终将代码更改为:

Pattern.compile(patternblue, Pattern.DOTALL).matcher(text).matches();

对于此特定的
模式
,您需要使用
DOTALL
标志,因为
蓝色
之后的
*
将与换行符不匹配

由于没有采用可选标志的
匹配
覆盖,您可能最终将代码更改为:

Pattern.compile(patternblue, Pattern.DOTALL).matcher(text).matches();