Revision: 24611
Updated Code
at March 5, 2010 04:32 by mangrar
Updated Code
//regular expression String patternStr = "(?=.*d.*d)(?=.*e)(?=.*b)(?=.*i)(?=.*t)(?=.*\\s)(?=.*c)(?=.*a)(?=.*r)^..........$"; boolean b; Matcher matcher; Pattern pattern; System.out.println("Regex pattern = "+patternStr); pattern = Pattern.compile(patternStr);//compiles the regex //validates bad credit System.out.println("Validating: bad credit"); matcher = pattern.matcher("bad credit"); b = matcher.matches(); if(b) System.out.println("bad credit: matched"); else System.out.println("bad credit: not matched"); //validates debit card System.out.println("Validating: debit card"); matcher = pattern.matcher("debit card"); b = matcher.matches(); if(b) System.out.println("debit card: matched"); else System.out.println("debit card: not matched");
Revision: 24610
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 5, 2010 04:01 by mangrar
Initial Code
//anagrams of patata String patternStr = "(?=.*p)(?=.*a.*a.*a)(?=.*t.*t)^......$"; String matcherStr = "patata"; System.out.println("patternStr = "+patternStr); Pattern p = Pattern.compile(patternStr); System.out.println("matcherStr = "+matcherStr); Matcher m = p.matcher(matcherStr); boolean b = m.matches(); System.out.print("Matches? "+b);
Initial URL
Initial Description
This is a snippet to validate anagrams of 'debit card'. It validates 'debit card' and 'bad credit'
Initial Title
Anagram Validator
Initial Tags
regex, java
Initial Language
Java