G
Guest
Now i need to match a string in a text file(actually a stored procedure
file), the code is like below:
private static void test1()
{
String regex =
"(-{128})(\\s*\\r\\n\\s*\\r\\n)(-{2})(\\s*)ADD(\\s*)YOUR(\\s*)CODE(\\s*)HERE\\r\\n((.|\\r|\\n)*)(-{2})(\\s*)END(\\s*)OF(\\s*)YOUR(\\s*)CODE\\r\\n\\r\\n(-{128})";
String text = readTextFromFile("C:\\test.txt");// read the text
file into a string
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
if(matcher.find())
{
System.out.println("matches");
}
else
{
System.out.println("Not match");
}
BufferedReader input = new BufferedReader(new
InputStreamReader(System.in));
try
{
input.readLine();
}
catch(IOException ex)
{
}
}
and unfortunately, it fails because of stack overflow, i guess jdk
mathes the regular expression in a recursive way, so when the regex is
some complicated, the stack overflows, is that right? and can someone
give me a explanation and help me solve this problem? thanks
file), the code is like below:
private static void test1()
{
String regex =
"(-{128})(\\s*\\r\\n\\s*\\r\\n)(-{2})(\\s*)ADD(\\s*)YOUR(\\s*)CODE(\\s*)HERE\\r\\n((.|\\r|\\n)*)(-{2})(\\s*)END(\\s*)OF(\\s*)YOUR(\\s*)CODE\\r\\n\\r\\n(-{128})";
String text = readTextFromFile("C:\\test.txt");// read the text
file into a string
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
if(matcher.find())
{
System.out.println("matches");
}
else
{
System.out.println("Not match");
}
BufferedReader input = new BufferedReader(new
InputStreamReader(System.in));
try
{
input.readLine();
}
catch(IOException ex)
{
}
}
and unfortunately, it fails because of stack overflow, i guess jdk
mathes the regular expression in a recursive way, so when the regex is
some complicated, the stack overflows, is that right? and can someone
give me a explanation and help me solve this problem? thanks