(城市 = 'pune' AND 国家 = '印度') OR (division = 'it') AND (resource = 'someresource' )
我想根据括号将其分成几组。
第 1 组 - (城市 = 'pune' AND 国家 = '印度')
第 2 组 - (division = 'it')
第 3 组 - (resource = 'someresource' )
有人可以提供 Java 示例的正则表达式吗?
最佳答案
试试这个:(演示:http://regexr.com?33u8e)
(\(.+?\))
代码示例(PHP):
<?php
$subject = "(city = 'pune' AND country = 'india') OR (division = 'it') AND (resource = 'someresource' )";
$pattern = '/(\(.+?\))/';
preg_match($pattern, $subject, $matches);
print_r($matches);
?>
<小时/>
另一种方法:尝试拆分(使用正向后视)
(?<=\))\s
<小时/>
编辑:最终答案(Java)
String[] parts = str.split("(?<=\\))\\s");
关于java - 需要 REGEX 帮助 - 分解行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15107248/