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 enter image description here

the selection above should possible selecting half of byte shouldn´t enter image description here

spaces @ end or beginning shouldn´t problem enter image description here

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

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -