Beginners Tutorial for Regular Expressions in Python | Python Learning

python
regular_expression

#1

The above article helps the beginners to scale up in python. I thank the author for this amazing piece of work. Also I have a doubt with respect to problem 2 under Some Examples of Regular Expressions

Please compare the below codes:

  1. Code given in the article

result=re.findall(r’\b\w.’,‘AV is largest Analytics community of India’)
print result

Output: [‘AV’, ‘is’, ‘la’, ‘An’, ‘co’, ‘of’, ‘In’]

  1. Code modified by me

result=re.findall(’\b\w.’,‘AV is largest Analytics community of India’)
print result

Output: []

Currently I run the code in Jupyter

When I removed “r” from the actual code the output was a blank list. Can you please help me understand the scenario??

Thanks in advance and appreciate your help!!


#2

Hi @GirishHN,

Normal strings use the backslash character as an escape character for special characters. The r prefix tells the interpreter not to do this. So when you use ‘r’ it will give you the desired results while if you don’t use ‘r’ \ will escape from the string and you will get empty array as output.