Finding Plus Sign in Regular Expression

前端 未结 7 2302
陌清茗
陌清茗 2020-11-27 17:49
var string = \'abcd+1\';
var pattern = \'d+1\'
var reg = new RegExp(pattern,\'\');
alert(string.search(reg));

I found out last night that if you tr

相关标签:
7条回答
  • 2020-11-27 18:41

    You probably need to escape the plus sign:

    var pattern = /d\+1/
    

    The plus sign is used in regular expressions to indicate 1 or more characters in a row.

    0 讨论(0)
提交回复
热议问题