I want to get content between two comments in some file.
like a file x
#user code
alert("");
alert("");
#user code
{
===
====
}
#user code
alert("as");
alert("as");
#user code
i am using this regex pattern to match
final Pattern pat = Pattern.compile("//#User code\r?\n(.*)\r?\n//#User code" , Pattern.DOTALL);
but its matching from first #user code to end of the file.
pls help.
A quick fix is to use
.*?instead of just.*. The?changes the*into a non-greedy repetition, which will match up until the nearest#user code, instead of the furthest.