/ Published in: Java
                    
                                        
This is a snippet to validate anagrams of  'debit card'. It validates 'debit card' and 'bad credit'
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
//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
                    Subscribe to comments
                
                