Javascript + Regex = Nothing to repeat error?

后端 未结 5 1915
既然无缘
既然无缘 2020-11-29 06:54

I\'m new to Regex and I\'m trying to work it into one of my new projects to see if I can learn it and add it to my repitoire of skills. However, I\'m hitting a roadblock her

5条回答
  •  广开言路
    2020-11-29 07:34

    Building off of @Bohemian, I think the easiest approach would be to just use a regex literal, e.g.:

    if (name.search(/[\[\]?*+|{}\\()@.\n\r]/) != -1) {
        // ... stuff ...
    }
    

    Regex literals are nice because you don't have to escape the escape character, and some IDE's will highlight invalid regex (very helpful for me as I constantly screw them up).

提交回复
热议问题