import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = ".*\\s(\\d{11}|\\d{5}\\s\\d{3}\\s\\d{3}|\\d{5}\\s\\d{6}|\\d{14}|\\+\\d{12}|\\+\\d{3}\\s\\d{3}\\s\\d{3}\\s\\d{3}|\\d{4}\\s\\d{3}\\s\\d{3})\\s.*";
final String string = "fdsgf dsgfd ggfs s 07123452670 ar gs fgsdf gsdf\n"
+ "t hth rt hrth rth 07812 345 931 tr yrt rty \n"
+ "try erty tr ytr y 07412 123466 tr yert y\n"
+ "tery ert y 00447912345188 etry ert y\n"
+ "tery etr yrt yret +971557017442 ert yert yrety \n"
+ "et yetr yertytr ety ert y +971 557 856 832 etry rt ytr y\n"
+ "etr yerty etry erty 0414 934 993 erty etry etry";
final String subst = "$1";
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