tags:

views:

105

answers:

1

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

+6  A: 

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

Bart Kiers
Thanks a lot Bart
Amit
You're welcome Amit.
Bart Kiers
@Amit, please mark this answer as accepted.
Alan Moore