I have the following code segment:
function test(){
try {
---------------some contents-------
}
catch(e){
}
}
Now, I want the codes between the 1st pair of curly braces. The output should be like:
try {
---------------some contents-------
}
catch(e){
}
How can I do that with or without using Regex? I tried using the following regex:
Pattern p = Pattern.compile("\\{([^}]*)\\}");
Matcher m = p.matcher(s); // s contains each line of the above text
while (m.find()) {
System.out.println(m.group(1));
}
But, It only fetches contents if its there in a single line or no multiple lines of braces exist.