0

When I run these lines in a python console

from re import match
    
temp = "THIS/THAT"
match("^[A-Z]+/[A-Z]+$", temp)
match("^[A-Z]+\/[A-Z]+$", temp)

Both matches print out

<re.Match object; span=(0, 9), match='THIS/THAT'>

Why the backslash (or escaped forward slash) have no effect on the results?

Sam
  • 1,765
  • 11
  • 82
  • 176
  • `/` is not any special regex metacharacter, `\/` = `/`. Your patterns are equal. – Wiktor Stribiżew Mar 06 '21 at 22:11
  • @WiktorStribiżew So why is there no impact from escaping a non-special character – Sam Mar 06 '21 at 22:12
  • It is not an alphanumeric char, escaping a non-alnum char makes it match itself. `\,` matches the same way as `,`. Note that beginning with Python 3.6 "unknown escapes consisting of '\' and an ASCII letter now are errors." However, `/` is not a letter, you can escape it, but you do not have to. – Wiktor Stribiżew Mar 06 '21 at 22:13
  • What did you think it would do? – Shawn Mar 06 '21 at 22:48

0 Answers0