How do I match a string with quotation marks followed by a string in curly braces?

I need a regex expression to match a quoted string, then a space, then a parenthesis, then braces.

For example, this is the text I want to map in Java:

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

What would a regex be for?

Sorry, but I just got lost. I tried a lot of different things, but now I'm so shocked.

+3
source share
3 answers

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

+3
source

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));
}

Conclusion:

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

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

0

Source: https://habr.com/ru/post/1734958/


All Articles