JSFiddle - React, Tailwind, and code Playground
by ipr101
JavaScript
var subject = "1 bed,2 or 3 bed"
var myregexp = /(\d+) bed|(\d+) or (\d+) bed/img;
var match = myregexp.exec(subject);
while (match != null) {
if (match[1]) {
alert("Found 'x bed', x is '" + match[1] + "'");
}
else {
alert("Found 'x or y bed', x is '" + match[2] + "', y is '" + match[3] + "'");
}
match = myregexp.exec(subject);
}