I am checking for precedence in a string in my function. Is there a way to change my code to incorporate regex -- I am quite unfamiliar with regex, and though I have read some tutorials online, still not getting 'it' too well. So any guidance would really be appreciated.
For example in a string XLYZ, if the char after X is not L or C, the 'violation' statement gets printed. Here's the code below:
if (subtnString[cnt]=='X' && cnt+1<subtnString.length){
if(subtnString[cnt+1]!= 'L' || subtnString[cnt+1]!= 'C'){
System.out.println("Violation: X can be subtracted from L and C only");
return false;
}
}
Is there a way I can use regex to replace this code?