java - Regex checking runs infinite time -
i have written below regex that,this regex not match input; working loop runs infinite time. how resolve issue
string originalregex ="(?s)\\00|\\+adw-|\\+ad4-|%[0-9a-f]{2}|system[.][a-z]|javascript\\s*:|>(?:\".*|^'.*|[^a-z]'.*|'[^a-z].*|')[-+\\*/%=&|^~\"']|\\?.*<:|\\(\\s*[a-z]{2,}\\.[a-z]{2,}.*\\)"; string xmldata = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><configuration xmlns=\"http://www.example.com/api/2.2\" timestamp=\"str111\" version=\"2.2\"><domain account=\"4af17966-c841-4b97-a94a-edd7a0769\" /></configuration>"; string freetext = ">(?:\".*|^'.*|[^a-z]'.*|'[^a-z].*|')[-+\\*/%=&|^~\"']|\\?.*<:"; final pattern pattern_1 = pattern.compile(freetext); matcher matcher = pattern_1.matcher(xmldata); while (!matcher.find()) { system.out.println("good job"); }
java's .find()
method returns "true if, , if, subsequence of input sequence matches matcher's pattern" - see documentation. in code, if no matches found then:
while (!matcher.find()) { system.out.println("good job"); }
evaluates to:
while (!false) { system.out.println("good job"); }
or, simpler:
while (true) { system.out.println("good job"); }
thus, infinite loop.
Comments
Post a Comment