const regex = /([\,\s]*)(Ste |Ste. )/gi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('([\\,\\s]*)(Ste |Ste. )', 'gi')
const str = `12 Watershore Circle
825 Stewart Street
820 N Lincoln Way
9235 Bella Vista Way
P.O. Box 4438
9936 Stone Oak Way
599 Hamstead Drive
3941 Park Drive Ste 20 #147
3609 Bradshaw RD,ste H #107
7909 Walerga Road, Ste. 112, PMB 108
Options I've tried for what I want:
([\\,\\s]*)(Ste |Ste. )
([\\,\\s]+)(Ste |Ste. )
(\\,*[\\W]Ste[\\W]|\\,*[\\W]Ste\\.[\\W])
What the live results on my webpage seem to think these mean:
(\\,*[\\w]Ste[\\w]|\\,*[\\w]Ste\\.[\\w])
or
([\\,\\s]*)(Ste|Ste\\.)`;
// 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