import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?P<username>[a-zA-Z0-9.-_]+)@(?P<domain>[a-zA-Z0-9.-_]+)\\.(?P<ltd>[a-zA-Z0-9-_]+)";
final String string = "The mail or post is a system for physically transporting postcards, letters, and parcels.[1] A postal service can be private or public, though many governments place restrictions on private systems. Since the mid-19th century,yvannak54@gmail.com national postal systems have generally been established as a government monopoly, with a fee on the article prepaid. Proof of payment is usually in the form of an adhesive postage stamp, but a it123@gmail.com postage meter is also used for bulk mailing. Modern private postal systems are distinguished from national postal agencies by the terms \"courier\" or \"delivery service\".\n";
final String subst = "<a href=\"mailto:\\0\">${username}</a>";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html