Java Regex takes too long -
i have regex
"((\\s{0,2})\\p{xdigit}{2}\\s{0,2})*"
the user can select matching string byte dump 
the selection above should possible selecting half of byte shouldn´t 
spaces @ end or beginning shouldn´t problem 
the problem given regex takes far long match. can improve, problem?
edit:
so build solution case. thing need check ist beginning , end of string. removing spaces , check if first , last elements length of splitted string 1. splitting anyway because after parsing byte array.
string selection = dumptext.getselectiontext(); if (selection.equals(" ") || selection.equals(" ")){ return; } //remove spaces @ beginning while(selection.charat(0) == ' '){ selection = selection.substring(1); } //remove spaces @ end while(selection.charat(selection.length()-1) == ' '){ selection = selection.substring(0, selection.length()-1); } string[] splitted = selection.split("\\s{1,2}"); if(splitted.length == 0 || splitted[0].length()==1 || splitted[splitted.length-1].length()==1){ return; }
when asking simple, basic string comparison more efficient. in case interested in first 2 , last 2 characters.
so test (after validating length):
s.charat(0) != ' ' && s.charat(1) == ' ' && s.charat(s.length - 1) != ' ' && s.charat(s.length - 2) == ' ' although isn't fancy, fast. test if have single character , space, other way around @ end.
this works basic validation though.
Comments
Post a Comment