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

前端 未结 4 878
刺人心
刺人心 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:46

    Leon Timmermans got exactly what I was looking for. I would add one small improvement for those who come here later:

    /(?

    The additional ?: at the beginning of the (\\\\) group makes it not saved into any match-data. I can't imagine a scenario where I'd want the text of that saved.

提交回复
热议问题