JavaScript regex to replace a character ignoring HTML tags

前端 未结 2 1068
温柔的废话
温柔的废话 2021-01-24 08:02

Once again, I need some help and I appreciate you all for being here willing to help.
I\'m trying to implement a regex for a JavaScript function that will replace a string o

2条回答
  •  轮回少年
    2021-01-24 08:18

    This will work as long as the amounts are always formatted like $36.07.

    function getAmount (s) { 
      var r = /\$([^<]+)(\d+)/.exec(s); 
      return r[1]+r[2]; 
    }
    
    getAmount("$36.07");
    // returns "36.07"
    

提交回复
热议问题