r keyword in regular expression | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

r keyword in regular expression

What purpose does “r” serve in starting the regular expression string with it?

14th May 2018, 7:39 PM
Sadia Mukhtar
Sadia Mukhtar - avatar
3 Answers
+ 4
It declares the string as "raw", raw strings ignore the backslash (so no \n, \\, \t ect), these are also sometimes used for file paths
14th May 2018, 9:34 PM
TurtleShell - avatar
What does it mean to ignore it? I got the impression that the r made special characters not count, but in the contrary, they do count... What's going on? Can you give an example?
28th May 2018, 4:02 AM
Meir-Simchah - avatar
It means that: prefixing with an r merely indicates to the string that backslashes \ should be treated literally and not as escape characters for python
3rd Jun 2018, 4:59 AM
Cristian Baeza Jimenez
Cristian Baeza Jimenez - avatar