import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "https?:\\/\\/\\Kexample\\.com";
final String string = "<img class=\"aligncenter wp-image-27283 size-large\" src=\"http://example.com/wp-content/uploads/2017/04/image-3-1024x1024.jpeg\" alt=\"homemade chocolate recipe\" width=\"640\" height=\"640\" srcset=\"http://example.com/wp-content/uploads/2017/04/image-3-1024x1024.jpeg 1024w, http://example.com/wp-content/uploads/2017/04/image-3-300x300.jpeg 300w, http://example.com/wp-content/uploads/2017/04/image-3-768x768.jpeg 768w, http://example.com/wp-content/uploads/2017/04/image-3-696x696.jpeg 696w, http://example.com/wp-content/uploads/2017/04/image-3-1068x1068.jpeg 1068w, http://example.com/wp-content/uploads/2017/04/image-3-420x420.jpeg 420w, http://example.com/wp-content/uploads/2017/04/image-3-560x560.jpeg 560w, http://example.com/wp-content/uploads/2017/04/image-3.jpeg 1080w\" sizes=\"(max-width: 640px) 100vw, 640px\" />";
final String subst = "abc.host.prov.com";
final Pattern pattern = Pattern.compile(regex);
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