如何匹配带引号的字符串后跟大括号的字符串? [英] 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.
例如,这是文本I想要在Java中匹配:
For example this is the text I want to match in Java:
"'Allo 'Allo!" (1982) {A Barrel Full of Airmen (#7.7)}
正则表达式是什么?
对不起,但我真的很迷失。我尝试了很多不同的东西,但是现在我很失望。
Sorry, but I'm just really lost. I tried a lot of different things but now I'm so stumped.
推荐答案
应该这样做:
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));
}
输出:
"'Allo 'Allo!" (1982) {A Barrel Full of Airmen (#7.7)}
'Allo 'Allo!
1982
A Barrel Full of Airmen (#7.7)
这篇关于如何匹配带引号的字符串后跟大括号的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文