I need to detect currency and extract digit from such strings as "10 dollars", "dollars 10", etc. I use String.prototype.match() and regex
/((dollar|usd\$)\s*(\d+)|(\d+)\s*(dollar|usd\$))/i
But match() returns me for "10 dollars"
["10 dollar", "10 dollar", undefined, undefined, "10", "dollar"]
and for "dollar 10"
["dollar 10", "dollar 10", "dollar", "10", undefined, undefined]
How I can avoid that situation and get predictable digit position ?
/(\d+)\ (dollar|usd)|(dollar|usd)\ (\d+)/gi