How do I match a quoted string followed by a string in curly brackets?
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.
"[^"]*"\s*\([^)]*\)\s*\{[^}]*\}
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)
"[^"]+"\s([^)]+)\s{[^}]+}
精彩评论