const regex = /(?<!\S)(?:[1-9]\d\d?,\d{3}|(?:[1-9]\d?|1[0-4]\d),\d{3},\d{3}|150,000,000)(?!\S)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<!\\S)(?:[1-9]\\d\\d?,\\d{3}|(?:[1-9]\\d?|1[0-4]\\d),\\d{3},\\d{3}|150,000,000)(?!\\S)', 'gm')
const str = `10,000
10,001
10,100
100,000
999,999
149,999,999
150,000,000
55,555
99,999
73,129
834,101
1,333,333
149,000,000
20,111,000
99,001,000
10,001,000
10,999,999
2,999,999
950,000
999,999
910,000
949,999
950,000
949,999,999
1,999,999,999
100,949,999,999
1
1,0
9,000
9,999
5,555
250,000,000
9,999
100000
150,000,001
150,000,100
150,001,000
150,100,000
151,000,000
9,150,000,000
160,000,000
000,000,000
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions