program A {
int x = 10;
tuple date {
int day;
int month;
int year;
}
}
function B {
int y = 20;
...
}
process C {
more code;
}
I’d like to extract whatever is inside the curly braces following A, B, C. I write the following code, but it does not work.
public class Test {
public static void main(String[] args) throws IOException {
String input = FileUtils.readFileToString(new File("input.txt"));
System.out.println(input);
Pattern p = Pattern.compile("(program|function|process).*?\\{(.*?)\\}\n+(program|function|process)", Pattern.DOTALL);
Matcher m = p.matcher(input);
while(m.find()) {
System.out.println(m.group(1));
}
}
}
Anyone could tell what I didn’t get right?
I’ve tested the regular expression in Javascript and it worked. See here.
try
output
still I think this would be more reliable