javascript - Word boundary not working for amount in dollars (REgex) -


this question has answer here:

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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -