Escaping Parentheses in Regex

前端 未结 4 2021
盖世英雄少女心
盖世英雄少女心 2020-12-09 03:17

I have a regex which has optional anchors at the end e.g.

(\\.|,|\\/)

I am trying to add \")\" to this but if I escape it

         


        
相关标签:
4条回答
  • 2020-12-09 03:24

    Your regex should look like this: (\.|,|\/|\))

    Test it out with http://rubular.com/

    0 讨论(0)
  • 2020-12-09 03:25

    If you want to match one of a set of character, it's best to use a character class. And within such a class, most escaping rules don't apply.

    So to match a dot, comma, slash or closing parenthesis, you can use

    [.,/)]
    
    0 讨论(0)
  • 2020-12-09 03:41

    \) is the correct way for escaping a paranthesis. Make sure you are properly escaping the \(\\) in the string literal.

    0 讨论(0)
  • 2020-12-09 03:46

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