import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "([0-9a-f]{2})([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?([0-9a-f]{2})?";
final String string = "some random text 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122\n"
+ "and more text";
final String subst = "\\t0x$1${2:+,0x$2:}${3:+,0x$3:}${4:+,0x$4:}${5:+,0x$5:}${6:+,0x$6:}${7:+,0x$7:}${8:+,0x$8:}${9:+,0x$9:}${10:+,0x$10:}${11:+,0x$11:}${12:+,0x$12:}${13:+,0x$13:}${14:+,0x$14:}${15:+,0x$15:}${16:+,0x$16:}\\n";
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