Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.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,环境:Java 我想匹配两个字符串之间的字符,下面是一个示例 foo <bar <foo@bar.com> xoo <xoo@bar.com> 基本上我想在两个字符串之间匹配字符,但我需要内部字符 非常感谢您的帮助?您可以使用此基于否定的正则表达式进行匹配: <[^<>]*> 在线演示: 或者仅使用lookarounds向您发送电子邮件: (?<=<)[^<>]*(?=>) (?使用以下正则表达式: &

环境:Java

我想匹配两个字符串之间的字符,下面是一个示例

foo <bar <foo@bar.com> xoo <xoo@bar.com>
基本上我想在两个字符串之间匹配字符,但我需要内部字符


非常感谢您的帮助?

您可以使用此基于否定的正则表达式进行匹配:

<[^<>]*>

在线演示: 或者仅使用lookarounds向您发送电子邮件:

(?<=<)[^<>]*(?=>)

(?使用以下正则表达式:

<([^<>]+)>
您可以在Java中看到这一点。

将实现这一点

因为“mathces ANYTHIN(也是“)”酒吧。 通过使用“[^]”你可以说任何话(比如“”),除了在帽子后面的方格内的字符

测试正则表达式的一个很好的站点是:)

(?<=<)[^<>]*(?=>)
<([^<>]+)>
String s = "foo <bar <foo@bar.com> xoo <xoo@bar.com>";

Pattern pattern = Pattern.compile("<([^<>]+)>");
Matcher matcher = pattern.matcher(s);

while(matcher.find()) {
    System.out.println(matcher.group(1));
}