Javascript match and extract $ symbol from a string?

后端 未结 4 895
孤街浪徒
孤街浪徒 2021-01-24 02:55

Currently I have:

var price = \'$4000\';
var currency = price.match([\\$]);
alert(currency);

However this doesn\'t seem to work. I would like t

4条回答
  •  爱一瞬间的悲伤
    2021-01-24 03:53

    This should work: '$4000'.match(/^\$/).

    (It looks for the $ sign at the beginning of the string)

    The javascript syntax for regular expression literal uses / at the beginning and at the end of the expression.

提交回复
热议问题