Here I have my money statements as MUR 30,000 or MUR 30000 or 30000 MUR or 30,000 MUR.
I have got already a regex which works for MUR 30000 and MUR 30,000.
/MUR \d+(,\d+)?/g
But now I need a regex that works for all four variants.
You can use the following regex pattern:
/(?:MUR\s)?\d{1,3}(?:,\d{3})*(?:\sMUR)?/g
(?:MUR\s)?: Match
You could match the digits part once, and then check if there is either MUR before or after it using lookaround assertions.
Note that you can surround the pattern with word boundaries \b to prevent partial word matches.
\d+(?:,\d+)?(?:(?<=MUR [\d,]+)|(?= MUR))
Regex demo
const regex = /\d+(?:,\d+)?(?:(?<=MUR [\d,]+)|(?= MUR))/g;
const s = `Here I have statements here my money in statement as MUR 30,000 or MUR 30000 or 30000 MUR or 30,000 MUR 3,0`;
console.log(s.match(regex));
Or use 2 alternations
(?<=MUR )\d+(?:,\d+)?|\d+(?:,\d+)?(?= MUR)
Regex demo
const regex = /(?<=MUR )\d+(?:,\d+)?|\d+(?:,\d+)?(?= MUR)/g;
const s = `Here I have statements here my money in statement as MUR 30,000 or MUR 30000 or 30000 MUR or 30,000 MUR 3,0`;
console.log(s.match(regex));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With