const regex = /(?<street>[\S \t]+?) ?(?<number>\d[\d\w-\/ ]*?$)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<street>[\\S \\t]+?) ?(?<number>\\d[\\d\\w-\\\/ ]*?$)', 'gm')
const str = `Wittenberger Straße 9221
Wittenberger Str. 92
Straße des 17. Juni 122a
Straße des 17 Juni 122a
Str. 545 3
Dr.-Külz-Ring 13
Kanalstraße 13 /1
Prager Str. 3 a
Prager Str. 3a
Prager Str. 3 asd
Erika-Mann-Straße 61 - 61s
Erik-Mann-Straße 61 - 62
Erika-Mann-Straße 61 -62
Erika-Mann-Straße 61b-61c-23d
Erika-Mann-Straße 61b/61c/23d/61b/61c/23d
dsaASa
III. Tongraben5
3. Tongrabe 5
55er Str. 5
%§\$§§ 2
`;
// 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