I'm trying to run this regular expression statement in Java. It should return false because the regex mandates there should only be an O,P,L, or H at the eighth position if there is an "A" in the third position.
System.out.println("TLN7HRNO".matches("[-LBQTHWROMSNT](0MIL|[LBCDGJKMNPQSTUVWXYZ][NA][0137CUVRT][PCBMVWTHKNDG])(NR|RR)(?(?<=A[A-Z0-9]{4})[OPLH]|$)"));
However, Java is not liking the IF-THEN-ELSE statement even though my regex editor worked just fine with it.
Does Java have a different implementation for IF-THEN-ELSE or does it just not support it all all.
java.util.regex.PatternSyntaxException: Unknown inline modifier near index 81
...[PCBMVWTHKNDG])(NR|RR)(?(?<=A[A-Z0-9]{4})[OPLH]|$)
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.group0(Unknown Source)
at java.util.regex.Pattern.sequence(Unknown Source)
at java.util.regex.Pattern.expr(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.<init>(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.matches(Unknown Source)
at java.lang.String.matches(Unknown Source)
at com.swa.rm.pricing.PFCLInterface.launchCLInterface(PFCLInterface.java:45)
at com.swa.rm.pricing.PFCLInterface.main(PFCLInterface.java:24)
[-LBQTHWROMSNT](0MIL|[LBCDGJKMNPQSTUVWXYZ][NA][0137CUVRT][PCBMVWTHKNDG])(NR|RR)(?:(?<=A[A-Z0-9]{4})[OPLH]|$)Patternclass. Any syntax that isn't listed there, isn't supported. Note that there is no (?X) (but as noted above, (?:X) might be what you're looking for.(?X)and(?:X)are two wholly different things. OP is looking for an IFTHENELSE regex statement not a non-capturing group. @yshavit look here:regex101.com/r/qC1jJ3/1