import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<!\\S)(?:[1-9]\\d\\d?,\\d{3}|(?:[1-9]\\d?|1[0-4]\\d),\\d{3},\\d{3}|150,000,000)(?!\\S)";
final String string = "10,000\n"
+ "10,001\n"
+ "10,100\n"
+ "100,000\n"
+ "999,999\n"
+ "149,999,999\n"
+ "150,000,000\n"
+ "55,555\n"
+ "99,999\n"
+ "73,129\n"
+ "834,101\n"
+ "1,333,333\n"
+ "149,000,000\n"
+ "20,111,000\n"
+ "99,001,000\n"
+ "10,001,000\n"
+ "10,999,999\n"
+ "2,999,999\n"
+ "950,000\n"
+ "999,999\n"
+ "910,000\n"
+ "949,999\n"
+ "950,000\n\n"
+ "949,999,999\n"
+ "1,999,999,999\n"
+ "100,949,999,999\n"
+ "1\n"
+ "1,0\n"
+ "9,000\n"
+ "9,999\n"
+ "5,555\n"
+ "250,000,000\n"
+ "9,999\n"
+ "100000\n"
+ "150,000,001\n"
+ "150,000,100\n"
+ "150,001,000\n"
+ "150,100,000\n"
+ "151,000,000\n"
+ "9,150,000,000\n"
+ "160,000,000\n"
+ "000,000,000\n\n\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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