0

I'm writing regular expressions in my DB. This question is not Why (I know why) is how to solve-it. I just solve the first match "\n" with the a.decode('string_escape'). But I don't know how to solve the "\s".

When Django returns me the field of the regex insted of my database field:

 "Detected PHP\nVersion:\s"

Returns me:

 "Detected PHP\\nVersion:\\s"

for me, retrieve the value unmodified or be able to change \n for \n and \s for \s are useful.

I'm trying:

**Replace works but only with print
>>> print a.replace('\\\\', '\\')
Detected PHP\nVersion:\s

>>> a.replace('\\\\', '\\'))
'Detected PHP\\nVersion:\\s'

Also decode string_escape works, but just with the \n not with \s:

a.decode('string_escape')
'Detected PHP\nVersion:\\s'

I want to recover from my db the string without the double slashes. Any help would be appreciated.

Zartch
  • 867
  • 9
  • 24
  • 7
    http://stackoverflow.com/questions/24085680/why-do-backslashes-appear-twice – Shang Wang Jul 25 '16 at 14:53
  • This question is not Why. is how to solve-it. And I just solve the first match \\n with the a.decode('string_escape'). But I don't know how to solve the \\s. – Zartch Jul 26 '16 at 09:05
  • Possible duplicate of [How do I un-escape a backslash-escaped string in python?](http://stackoverflow.com/questions/1885181/how-do-i-un-escape-a-backslash-escaped-string-in-python) – Laurel Jul 31 '16 at 21:12

0 Answers0