How it works...

The regular expression string was defined to match a simple pattern: multiple characters followed by an ampersand, and then by more characters terminated by a period. This is followed by two to four characters typically representing an internet domain, such as .net or .com:

String emailRegularExpression = "[a-zA-Z0-9'._%+-]+@" + 
"(?:[a-zA-Z0-9-]+\.)" + "+[a-zA-Z]{2,4}";

The Pattern class is an internal representation of a regular expression created using the static compile method executed against the regular expression string. The matcher instance finds the instance of the regular expression:

Pattern pattern = Pattern.compile(emailRegularExpression);
Matcher matcher = pattern.matcher(sampleText);

The find method was then used to identify the next embedded entity. Each invocation of the method will result in the Matcher instance pointing to the next entity. It will return true if it finds one. The group method returns the following entity:

while (matcher.find()) {
System.out.println(matcher.group());
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.194.182