I have this regex
"((\\s{0,2})\\p{XDigit}{2}\\s{0,2})*"
the user can select the matching string from Byte dump like this

the selection above should be possible but selecting half of a Byte shouldn´t like this

spaces at the end or beginning shouldn´t be a problem like this

the problem with the given regex is that it takes far too long to match. what can i improve, what is the problem?
edit:
so i build a solution for this case. the only thing i need to check ist the beginning and the end of the string. removing the spaces and check if the first and last elements length of the splitted string is 1. I am Splitting it anyway because after that i am parsing it to a byte Array.
String selection = dumpText.getSelectionText();
if (selection.equals(" ") || selection.equals(" ")){
return;
}
//remove spaces at the beginning
while(selection.charAt(0) == ' '){
selection = selection.substring(1);
}
//remove spaces at the 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;
}
Stringtoo big? If it is performed often you can compile once and just use a matcher multiple times (if you don't do that already).