0
我有一个要求,其中结果屏幕显示(),[]中的名称。例如:正则表达式或条件
(son of X) (Smith),(son of X) Smith
[Son of X] Smith
[Son of X] [Smith]
我想检索它的名字。我想第一个字符串下面的正则表达式,但它并不能帮助:
String name="(son of x) (Smith)";
Matcher matcher = Pattern.compile("\\(.*\\)\\b").matcher(name);
while (matcher.find()) {
System.out.println(matcher.group());
}
有人可以帮助形成正则表达式?还请让如何给一个或条件?
在[Javadoc](https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html)中搜索“X或Y”。 –
你想要的确切输出是什么? – IfOnly
试试[']^[(\\ []。*?[)\\]] \\ W *(\\ w +)“'](https://regex101.com/r/PrFogN/1)regex和获取组1('matcher.group(1)')中的值。 –