Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Regular Expressions in Python Introduction to Regular Expressions Groups

Sahar Nasiri
Sahar Nasiri
7,454 Points

What is different between real space and \s?

Why should we write for example this: print(re.findall(r'\d\s')) What is wrong with print(re.findall(r'\d '))?

3 Answers

Guy Scorpion
Guy Scorpion
11,053 Points

\s is for any white space. It will search for regular space, tab, new line etc.

Camille Ferré
Camille Ferré
3,330 Points

Hi Guy,

So then when would we use a real space? why not use \s all the time ?

Thanks

Hey I found another Tutorial in the Python documentation which is not so compicated written like the most other stuff in the python docs: https://docs.python.org/2/howto/regex.html

Its more easy to read. There is also a section called "The Backslash Plague" :D

I am not rly fit in python but here is everything you need to know about Regular expressions: https://docs.python.org/2/library/re.html

The official python reference/documentation is always a good source to get informations

Guy Scorpion
Guy Scorpion
11,053 Points

Hi Camille, It really depends on your situation. There may be an occasion where you need to select spaces only and leave tab spacing or other white space characters. \s is the equivalent of using [ \t\n\r\f\v] which is [space, tab, new line, carriage return, form feed, vertical tab]. Form feed I believe is another term for page break.

Camille Ferré
Camille Ferré
3,330 Points

Thanks for your reply, I guess I will better understand when I face this situation. Thanks for the clarification.