I want to include the ‘\’ character in the regex replacement. For example:
E{bla} -> \bla
The statement I use (in ruby) is
text.gsub!(/\\E{(\w*)}/, '\\\1')
but I get
E{bla} -> \1
instead. How do I get what I want?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ll need 6 backslashes like this:
The
\\\\\\1gets passed to gsub as\\\1(the 1st, 3rd and 5th backslashes each escape the following backslash). This is interpreted by the regexp engine as\followed by\1(the first backslash escapes the second backslash)