const regex = /(\b(?:\w+)?\d+(?:\w+)?(?:[\-\/])?(?:\w+)?(?:\d+)?\b)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\b(?:\\w+)?\\d+(?:\\w+)?(?:[\\-\\\/])?(?:\\w+)?(?:\\d+)?\\b)', 'g')
const str = `Park Avenue number 100
Baker Street number 100
Baker Street 100
The bakery shop is located on 109-111 Wharfside Street
My mother's house is on 40-42 Parkway
My schoolmate lives in 25b-26 Sun Street
The apartment is located on R2-R3 City Quay
I live in 43a Garden Walk
I live in 6/7 Marine Road
I live in 10-12 Acacia Ave
I live in 4513 3RD STREET CIRCLE WEST
I live in 1/2 Fifth Avenue
number C3-H4 sawojajar Malang`;
// 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