Simply you can use this package for the same .
java.util.regex.Matcher for matching pattern and java.util.regex.Pattern for Regex.