RegEx - How to Extract Price?

前端 未结 5 577
名媛妹妹
名媛妹妹 2020-12-06 19:19

How would I extract the dollar amount from the following string

\"some text will go here and more and more and then there will be some price $34.03 but that doesn\'t

5条回答
  •  感动是毒
    2020-12-06 19:43

    I'm no regex-guru, but was able to whip up the following with RegExr.

    /(\$[0-9]+(\.[0-9]{2})?)/
    

    Matches $35.03 and $35. To accept formats like $35,000.52 you would need to include ,

    /(\$[0-9,]+(\.[0-9]{2})?)/
    

    This could likely be improved upon, but from my preliminary tests, it works just fine.

提交回复
热议问题