4

I have a pattern @@{} and given a string I need to find out all the strings coming in between the curly braces.

Example : If my string is Hi This is @@{first} and second is @@{second} along with third @@{third} string

The output I expect is a string array consisting of elements:

first   
second  
third

My Java code for this goes as :

Pattern p = Pattern.compile("\\@\\@\\{(.+?)\\}");    
Matcher match = p.matcher("Hi This is @@{first} and second is @@{second} along" +
                          "with third @@{third} string");
while(match.find()) {
    System.out.println(match.group());   
}

But the output which I am getting is

@@{first}   
@@{second}  
@@{third}

Please guide me how to get the desired output and what mistake I am doing

2
  • 2
    By the way, looking at your earlier questions... if an answer solves your problem, don't forget to mark it as "accepted" by ticking the green checkmark on the left. Commented Nov 10, 2009 at 7:51
  • 1
    +1 for very clearly written question Commented Nov 10, 2009 at 8:54

1 Answer 1

7

Change match.group() into match.group(1). Also, @ needs no escaping.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.