Finding Plus Sign in Regular Expression

前端 未结 7 2321
陌清茗
陌清茗 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.

提交回复
热议问题