RegEx - How to Extract Price?

前端 未结 5 578
名媛妹妹
名媛妹妹 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:34

    What about this regexp: \$[0-9.,]+ or \$([0-9.,]+) to strip the $?

    It's simple but it does pretty much what you want, it even catches things like this: $1,450.8934 or $14.343.

    Of course the drawback it'd be that it'd catch $34.54.23 as well.

    Or if you want to catch only two decimals: \$[0-9,]+\.[0-9]{2} it'd catch the $5.23 part of $5.234565.

    You can use it with preg_match or preg_match_all.

提交回复
热议问题