Ok I have a String that I’m parsing and I need to use toUpperCase() on that string. After that I’m using Java RegExp. Problem is that for some reason the Java’s String toUpperCase() is modifying the white spaces and my RegExp will not work.
Is there a way to tell toUpperCase() to ignore white spaces? Or maybe its possible to handle this in RegExp?
Below is the code I’m using to figure this out. If I uncomment the toUpperCase() line below, my RegExp will not work!!
String regExp = "([t][o][k][e][n][\\s]*[=][\\s]*)";
String content = "The token ='testing'" ;
//content = content.toUpperCase(); //uncomment this and RegExp will break!!!
Pattern pattern = Pattern.compile(regExp);
Matcher matcher = pattern.matcher(content);
if(matcher.find()){
int startIndex= matcher.start(1);
int endIndex = matcher.end(1);
String posStartExpression = content.substring(startIndex,endIndex);
System.out.println(posStartExpression);
}
You are encountering this behaviour because your regex is case sensitive.
Try this: