import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "((?:[+-])?(?:(?:0?\\.[0-9]*)|(?:[1-9]+\\.?[0-9]*))(?:[eE][+-]?(?:(?:0?\\.[0-9]*)|(?:[0-9]+\\.?[0-9]*)))?)|(0x[0-9a-fA-F]+)|(0[0-9]*)";
final String string = "Matching Groups:\n"
+ "===============================\n"
+ "Group 0x1: hexadecimal numbers\n"
+ "Group 02: octal numbers\n"
+ "Group 3: decimal numbers\n\n"
+ "1, 04, 3., +1.2e4, -0.03E-4, -.456E+003, - 04, .e4, 1.3e\n\n"
+ "-0.04e-03 0x024 0 0x 0xG 0xF 0xf 0x3.4 0123345\n\n"
+ "-00 -0xf.3e0f 0xFF00233 e09 e0xk22";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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