I'll start with an example:
Assuming the following input (assume that \n is a line break):
MY STRING content1 \n content1; my string content2 \n \n content2; my string content3 content3 \n content3
As you can see, the first two parts end with a ';' character, but the last one doesn't. The following regex pattern match will fetch both first parts, but not the second part:
Matcher m = Pattern.compile("(MY STRING(.*?)\\;)|(my string(.*?)\\;)").matcher(str);
The result is:
MY STRING content1 \n content1;
my string content2 \n \n content2;
But I didn't get:
my string content3 content3 \n content3
Is there a way to match a string that ends with either ";" or when the entire string ends (like the last part)?