You need to the use the Pattern and Matcher classes. See Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)