0
Why pattern = r"\b(cat)\b" should match with ">cat<"? Don't the boundaries should be the same symbol?can they be also brackets?
I am trying to understand regular espressions in python with the module re
2 Respostas
+ 1
Brackets have a special meaning for regular expressions. To use them in your expression as regular brackets, add a backslash before them: \( \).
+ 1
pattern = r"\b(cat)\b"
where \b = the empty string (not words) between word characters.
so > and < is not a word, therefore Python considers it an empty space.
I hope this helps!