Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.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/17.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 重写此regexp以仅在存在其他字符时匹配_Java_Regex - Fatal编程技术网

Java 重写此regexp以仅在存在其他字符时匹配

Java 重写此regexp以仅在存在其他字符时匹配,java,regex,Java,Regex,我有这个regexp Pattern pattern = Pattern.compile("\\{([^\\}]+)\\}"); 匹配{a1 | a2 | a3}和{a4}格式 我如何重写上面的行,以便仅在管道|存在时包含这些匹配,以便匹配{a1 | a2 | a3}而不匹配{a4}将管道字符添加到正则表达式中: "\\{([^\\}]+\\|[^\\}]+)\\}"

我有这个regexp

Pattern pattern = Pattern.compile("\\{([^\\}]+)\\}");
匹配{a1 | a2 | a3}和{a4}格式


我如何重写上面的行,以便仅在管道|存在时包含这些匹配,以便匹配{a1 | a2 | a3}而不匹配{a4}

将管道字符添加到正则表达式中:

"\\{([^\\}]+\\|[^\\}]+)\\}"