const regex = /^(\+){0,1}254(110|111|112|113|114|115|116|117|118|119|701|700|702|703|704|705|706|707|708|709|710|711|712|713|714|715|716|717|718|719|720|721|722|723|724|725|726|727|728|729|740|741|742|743|745|746|748|757|758|759|767|768|769|790|791|792|793|794|795|796|797|798|799)(\d{6})$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(\\+){0,1}254(110|111|112|113|114|115|116|117|118|119|701|700|702|703|704|705|706|707|708|709|710|711|712|713|714|715|716|717|718|719|720|721|722|723|724|725|726|727|728|729|740|741|742|743|745|746|748|757|758|759|767|768|769|790|791|792|793|794|795|796|797|798|799)(\\d{6})$', 'gm')
const str = ``;
// 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