javascript - Word boundary not working for amount in dollars (REgex) -
this question has answer here:
- how reduce complexity in regex? 3 answers
i have regex match amount in $.
(\-?\$\-?[0-9]+\.?[0-9]*|usd\-?[0-9]+\.?[0-9]*|[0-9]+\.?[0-9]*\-?usd|[0-9]*\.?[0-9]*\$)
currently matching $250, usd250 etc, should not match $250 in $250abchhh.
so, tried word boundary, didn't fix issue well, how can fix issue?
matching cases
$456 $45.6 $.5 $-45 -$45 usd-456 usd46 usd4.6 usd.46 1$ 1.5$ .5$ -.5$ 5usd 456usd
it should not match
455$abc abc$123 abcuds1 jhb$5665usdjnjnb $usd1555 usd$768 $566usd $5788usdbjhj
you should write correct regex decimal. , use ^$ start , end of line.
^\s*(?:(?:(?:-?(?:usd|\$)|(?:usd|\$)-)(?:(?:0|[1-9]\d*)?(?:\.\d+)?(?<=\d)))|(?:-?(?:(?:0|[1-9]\d*)?(?:\.\d+)?(?<=\d))(?:usd|\$)))\s*$
look here @ test results.
Comments
Post a Comment