I have the following pattern contained n times in a file:
ENUM CMF_QUOTE_EVENT
CMF_QUOTE_EVENT_Activate "Activate"
CMF_QUOTE_EVENT_Suspend "Suspend"
CMF_QUOTE_EVENT_Delete "Delete"
ENDENUM
My goal is to catch all the values of the enum. Basically I need the three lines between the keywords "ENUM" and "ENDENUM".
I tried to use a Multiline Regex for that but I still can't catch it. Here's I did it:
BufferedReader br = new BufferedReader(new FileReader(file));
String line = "";
StringBuilder sb = new StringBuilder();
while ((line = br.readLine()) != null)
{
sb.append(line.replace("\\s",""); // delete tabs and ws
}
Pattern pattern= Pattern.compile("ENUM(.*)(.|\\s)*ENDENUM", Pattern.MULTILINE);
Matcher match = pattern.matcher(sb.toString());
while (match.find())
{
// do something
}
br.close();
I am wondering using a grammar instead, but it looks very heavy for this only use. Can I do this kind of thing with a regex?
Thank you all