问题
I need a regex expression for matching a string in quotes and then a white space then a round bracket then a curly bracket.
For example this is the text I want to match in Java:
"'Allo 'Allo!" (1982) {A Barrel Full of Airmen (#7.7)}
What would the regex for this be?
Sorry, but I'm just really lost. I tried a lot of different things but now I'm so stumped.
回答1:
"[^"]*"\s*\([^)]*\)\s*\{[^}]*\}
回答2:
This should do it:
Pattern p = Pattern.compile("\"(.*?)\"\\s+\\((\\d{4})\\)\\s+\\{(.*?)\\}");
Matcher m = p.matcher("\"'Allo 'Allo!\" (1982) {A Barrel Full of Airmen (#7.7)}");
if (m.find()) {
System.out.println(m.group());
System.out.println(m.group(1));
System.out.println(m.group(2));
System.out.println(m.group(3));
}
Output:
"'Allo 'Allo!" (1982) {A Barrel Full of Airmen (#7.7)}
'Allo 'Allo!
1982
A Barrel Full of Airmen (#7.7)
回答3:
"[^"]+"\s([^)]+)\s{[^}]+}
来源:https://stackoverflow.com/questions/2359330/how-do-i-match-a-quoted-string-followed-by-a-string-in-curly-brackets