S
Saad Malik
Hi Guys/Gals
I got a quick question on regex. My input string consists of two
characters: [a-z][a-z].. However, I only want to match if the two
characters are different.
Example: ab,ck,dk,gk... are all valid, but aa,bb,cc,dd,ee... should not
match..
This is the regex I have so far, but it does not seem to work:
([a-z])(?!\1)[a-z]
complete program:
Pattern pat2 = Pattern.compile("([a-z])(?!\1)[a-z]");
Matcher m = pat2.matcher("aa");
System.out.println(m.matches()); THIS PRINTS TRUE but aa should not be
true.
Thanks in Advance,
Saad.
I got a quick question on regex. My input string consists of two
characters: [a-z][a-z].. However, I only want to match if the two
characters are different.
Example: ab,ck,dk,gk... are all valid, but aa,bb,cc,dd,ee... should not
match..
This is the regex I have so far, but it does not seem to work:
([a-z])(?!\1)[a-z]
complete program:
Pattern pat2 = Pattern.compile("([a-z])(?!\1)[a-z]");
Matcher m = pat2.matcher("aa");
System.out.println(m.matches()); THIS PRINTS TRUE but aa should not be
true.
Thanks in Advance,
Saad.