angad Soni
angad Soni

Reputation: 321

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.

Upvotes: 3

Views: 307

Answers (3)

cletus
cletus

Reputation: 625037

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)

Upvotes: 3

jsight
jsight

Reputation: 28409

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

Upvotes: 0

Mark Byers
Mark Byers

Reputation: 838046

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

Upvotes: 3

Related Questions