const regex = new RegExp('(\\+?(?:(84|0))(\\s?[\\-\\u2010\\u2011\\u2012\\u2013\\u2014\\u2015]?\\s?)[357-9]\\d{6}(?:\\d{2}(?:\\d{1})?)?)', 'gm')
const str = `1234567
76543211234
123456789
12345778
1234567890
+8412345678
84123456789
8412345
84123456
+1234567
+84
0123456
+84356763987
5123456
31234567
712345678
9123456789
+84-5123456
+84 5123456
05123456
0-5123456
+84 - 5123456
843378262
84337671542
84575516147
`;
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