/ Published in: Java
This is a snippet to validate anagrams of 'debit card'. It validates 'debit card' and 'bad credit'
Expand |
Embed | Plain Text
//regular expression String patternStr = "(?=.*d.*d)(?=.*e)(?=.*b)(?=.*i)(?=.*t)(?=.*\\s)(?=.*c)(?=.*a)(?=.*r)^..........$"; boolean b; Matcher matcher; Pattern pattern; pattern = Pattern.compile(patternStr);//compiles the regex //validates bad credit matcher = pattern.matcher("bad credit"); b = matcher.matches(); //validates debit card matcher = pattern.matcher("debit card"); b = matcher.matches();
Comments
Subscribe to comments
You need to login to post a comment.

A better example:
//Example: bad credit debit card String patternStr = "(?=.d.d)(?=.e)(?=.b)(?=.i)(?=.t)(?=.\s)(?=.c)(?=.a)(?=.r)^..........$"; String matcherStr = "bad credit";