How do I match a quoted string followed by a string in curly brackets?

元气小坏坏 提交于 2020-01-04 05:22:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!