import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(^.*\\/.*-(.*))";
final String string = "https://i.ibb.co/cb1sZCc/featured-crown-dark-turquoise.png\n"
+ "https://i.ibb.co/9qVswyn/featured-crown-gold.png\n"
+ "https://i.ibb.co/fxQPh6q/featured-crown-gray.png\n"
+ "https://i.ibb.co/zxZJGj9/featured-crown-green.png\n"
+ "https://i.ibb.co/sgV0QJh/featured-crown-magenta.png\n"
+ "https://i.ibb.co/mNFdFMJ/featured-crown-orange.png\n"
+ "https://i.ibb.co/hDSZ7wn/featured-crown-original.png\n"
+ "https://i.ibb.co/nCvqhKG/featured-crown-purple.png\n"
+ "https://i.ibb.co/d71yh86/featured-crown-red.png\n"
+ "https://i.ibb.co/Smc4y6B/featured-crown-saddle-brown.png\n"
+ "https://i.ibb.co/GPP4mRJ/featured-crown-teal.png";
final String subst = " { \"id\": \"string\", \"heading\": \"Heading: $2\", \"subheading\": \"Subheading: $2\", \"image\": \"$1\", \"weblink\": \"http://wattpad.com/home\", \"applink\": \"wattpad://home\" },";
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