What is the proper regular expression for an unescaped backslash before a character?

前端 未结 4 869
刺人心
刺人心 2020-12-31 11:18

Let\'s say I want to represent \\q (or any other particular \"backslash-escaped character\"). That is, I want to match \\q but not \\\\q

4条回答
  •  庸人自扰
    2020-12-31 11:57

    The best solution to this is to do your own string parsing as Regular Expressions don't really support what you are trying to do. (rep @Frank Krueger if you go this way, I'm just repeating his advice)

    I did however take a shot at a exclusionary regex. This will match all strings that do not fit your criteria of a "\" followed by a character.

    (?:[\\][\\])(?!(([\\](?![\\])[a-zA-Z])))
    

提交回复
热议问题