0

In python regular expression, raw string behavior is different.

import re
m = re.match(r"\n","C:\some\nDay\n")
print(m)
a= re.match("\n", "C:\some\nDay\n")
print(a)

In the first expression, it should consider \n as normal text and return the match position. but in both expression None is the output.

Mathan S
  • 1
  • 2
  • 3
    The behavior is different, but the results are the same? Care to revise your question? – Ignacio Vazquez-Abrams Oct 14 '16 at 10:33
  • `match()` will work if you for instance do `re.match(r'[^\n]*\n+', 'C:\some\nDay\n', re.M)`. But also know that `C:\some` is not escaped, meaning `\s` is escaped. – Torxed Oct 14 '16 at 10:38
  • re.match(r'[^\n]*\n+', 'C:\some\nDay\n', re.M) and re.match('[^\n]*\n+', 'C:\some\nDay\n', re.M) --> results are same – Mathan S Oct 14 '16 at 10:40

0 Answers0