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 trialSahar Nasiri
7,454 PointsWhat 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
11,053 Points\s is for any white space. It will search for regular space, tab, new line etc.
tobiaskrause
9,160 PointsI 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
11,053 PointsHi 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é
3,330 PointsThanks for your reply, I guess I will better understand when I face this situation. Thanks for the clarification.
Camille Ferré
3,330 PointsCamille Ferré
3,330 PointsHi Guy,
So then when would we use a real space? why not use \s all the time ?
Thanks
tobiaskrause
9,160 Pointstobiaskrause
9,160 PointsHey 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