Canada zip code format regex

Effective regular expression to validate Canada zip code format : String regex = "^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$"; Pattern pattern = Pattern.compile(regex); if(!pattern .matcher("postcode").matches()) {         System.out.println("This is CA zip code"); }

Advertisements

Palindrome and Prime

the initial drafted title was "Old concepts with new understanding". You'll know why. Palindrome : A string which is same when read from left to right or right to left. Algorithm as a naive programmer : Run a loop till middle of string, and compare the first letter with last letter, then 2nd with second …