Match dynamic string using regex

后端 未结 4 540
旧巷少年郎
旧巷少年郎 2020-12-02 00:26

I\'m trying to detect an occurrence of a string within string. But the code below always returns \"null\". Obviously something went wrong, but since I\'m a newbie, I can\'t

4条回答
  •  佛祖请我去吃肉
    2020-12-02 00:47

    Please don't put '/' when you pass string in RegExp option

    Following would be fine

    var strRegExPattern = '\\b'+searchStr+'\\b'; 
    "32:width: 900px;".match(new RegExp(strRegExPattern,'g'));
    

提交回复
热议问题