On simple words , these regex or  Regular Expressions are used to validate the E-mail address, URL, phone no’s etc.The regular expression is a string of characters that describes a character sequence. You can specify a regular expression that represents a general form that can match several different specific character sequences. They can be used to scan text to extract data embedded in bulk of datas, edit, or manipulate text and data. This explains how to use the “java.util.regex” API for pattern resembling with regular expressions.
There are two classes that support regular expression processing:
Pattern:
The pattern is used to define a compiled representation of a regular expression. The pattern is created by calling public static compile factory method, which will return a pattern object. This compile method has one string argument that would be the regular expression that you want to use. Once you created pattern object, you will use it to create a Matcher.
Matcher:
The Matcher is an engine that interprets the pattern and performs the match operation against the input string. You can create a matcher object by invoking the matcher method on a pattern object by calling matcher factory method defined by the Pattern.
The simplest pattern matching method is ‘matches ()’. In this case the entire sequence must match the pattern not just the sub sequence of it. This matches method returns true if the sequence and pattern match and false otherwise. And no of other methods are using for different type matching operation.
Regular Expression Syntax:
Before creating Pattern and Matcher it is necessary to know how to construct a regular expression. For creating a Regular Expression there have some syntax and rules. These syntax and rules are same as that used in Perl5. A Regular Expression is comprised of normal characters, character classes, wildcard characters and quantifiers.
A normal character is matched as is. That is if a pattern consist of “xyz” then the only input sequence that will match it is “xyz”. In this Regular Expression each normal character is known as literals.
A character class means a set of literals. A character class is specified by putting the literals in the class between brackets. Example, the class [abcd] matches a, b, c or d. To specify the inverted set character class by ‘^’ symbol. Example, [^abcd] matches any character except a, b, c, or d. You can specify a range of character using a hypen. Examples, to represent a character class that will match the digits 1 through 9 use [1-9].
The wildcard characters is the ‘.’ (Dot) and it matches any character. Thus, a pattern that consist of ‘.’ Will match these input sequence “A”, “a”, “x” and so on.
A quantifier determines the number of times the expression is matched. The quantifiers shown below
“+” stands for match one or more.
“*” stands for match zero or more.
“?” stands for match zero or one.
Example, the pattern “x+” will match “x”, “xx” and “xxx” among others.