Last active
August 29, 2015 13:59
-
-
Save ninux/10648411 to your computer and use it in GitHub Desktop.
using regex in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private boolean containsNumbers(String s) { | |
Pattern p = Pattern.compile(".*\\d.*"); | |
return p.matcher(s).find(); | |
} | |
private boolean containsCharacters(String s){ | |
Pattern p = Pattern.compile("[a-zA-Z]"); | |
return p.matcher(s).find(); | |
} | |
private boolean containsOneAt(String s){ | |
int counter = 0; | |
Pattern p = Pattern.compile("[@]"); | |
Matcher m = p.matcher(s); | |
while(m.find()){ | |
counter++; | |
} | |
return counter == 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment