编译并打印出 "AED"。甚至对多个小括号也有效。
import java.util.regex.*;
public class Main
public static void main (String[] args)
String example = "United Arab Emirates Dirham (AED)";
Matcher m = Pattern.compile("\\(([^)]+)\\)").matcher(example);
while(m.find()) {
System.out.println(m.group(1));
该重词的意思是。
\\(
: character (
(
: start match group
[
: one of these characters
^
: not the following character
)
: with the previous ^
, this means "every character except )
"
+
: one of more of the stuff from the []
set
)
: stop match group
\\)
: literal closing paranthesis