import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "• (.+?)\\s+- FF([A-F0-9]{2})([A-F0-9]{2})([A-F0-9]{2})";
final String string = " • White - FFe4e4e4 \n"
+ " • Light Gray - FFa0a7a7 \n"
+ " • Dark Gray - FF414141 \n"
+ " • Black - FF181414 \n"
+ " • Red - FF9e2b27 \n"
+ " • Orange - FFea7e35 \n"
+ " • Yellow - FFc2b51c \n"
+ " • Lime Green - FF39ba2e \n"
+ " • Green - FF364b18 \n"
+ " • Light Blue - FF6387d2 \n"
+ " • Cyan - FF267191 \n"
+ " • Blue - FF253193 \n"
+ " • Purple - FF7e34bf \n"
+ " • Magenta - FFbe49c9 \n"
+ " • Pink - FFd98199 \n"
+ " • Brown - FF56331c";
final String subst = "\"$1\": [0x$2, 0x$3, 0x$4],";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
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