import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:(if\\s+)|\\|\\|\\s*)(?<attrName>[\\p{L}\\p{N}_-]+)(?==\")";
final String string = "<if VERSION=\"A1\" || VERSION=\"A3\"||VERSION=\"a2_%5C%22A3\">\n\n"
+ "<assign CTA=\"blue\"></assign>\n"
+ "<assign CTA2=\"green\"></assign>\n"
+ "<assign TEXT1=\"Hello%3Cbr/%3EWorld\"></assign>\n\n"
+ "<elseif attribute-name=\"A2\">\n\n"
+ "<assign CTA=\"red\"></assign>\n"
+ "<assign CTA2=\"yellow\"></assign>\n"
+ "<assign CTA3=\"brown\"></assign>\n"
+ "<assign TEXT1=\"Click%20%3Ca%20href='https://example.com'%20style='text-decoration:none;color:#000000;'%3Ehere%3C/a%3E\"></assign>\n\n"
+ "</if>\n\n"
+ "// condition 2\n"
+ "<if FOO_BAR=\"A4\" || baz-biz=\"A5\">\n\n"
+ "<assign CTA=\"purple\"></assign>\n"
+ "<assign CTA2=\"orange\"></assign>\n"
+ "<assign TEXT1=\"Hi%20%3Cspan%20style='font-%20weight:bold;'%3EJohn%3C/span%3E\" TEXT2=\"Hello%3Cbr/%3EWorld\"></assign>\n\n"
+ "</if>\n\n"
+ "// condition 3\n"
+ "<if LANG=\"en_US\">\n\n"
+ "<assign TITLE=\"English\"></assign>\n\n"
+ "</if>";
final String subst = "$1 $<attrName>";
final Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CASE);
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