如何匹配带引号的字符串后跟大括号中的字符串?

发布于 2024-08-23 18:24:00 字数 228 浏览 4 评论 0原文

我需要一个正则表达式来匹配引号中的字符串,然后是空格,然后是圆括号,然后是大括号。

例如,这是我想在 Java 中匹配的文本:

"'Allo 'Allo!" (1982) {A Barrel Full of Airmen (#7.7)}

What would the regex for this be?

抱歉,但我真的迷路了。我尝试了很多不同的事情,但现在我很困惑。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

提赋 2024-08-30 18:24:00

"[^"]*"\s*\([^)]*\)\s*\{[^}]*\}

"[^"]*"\s*\([^)]*\)\s*\{[^}]*\}

埋葬我深情 2024-08-30 18:24:00

这应该可以做到:

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)

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)
转角预定愛 2024-08-30 18:24:00

"[^"]+"\s([^)]+)\s{[^}]+}

"[^"]+"\s([^)]+)\s{[^}]+}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文