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 trialDaniel Petrov
3,495 PointsIs there a difference between space and \s?
Is there a difference between using space and \s in the sets and outside? In the name we use [-\w ] and in job we use [-\w\s]. Can we use just space when specifying the space between the words or only \s?
2 Answers
Steven Parker
231,248 Points A space just matches a space. The \s
code matches any kind of "white space", including space, tab, vertical tab, return, new line, and form feed.
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsDaniel Petrov, yes, \s should match almost any kind of whitespace, even letterspaces, tabs, halftabs, newlines etc. Negation 6:00 And, i guess, if you add + it will match 1x and 2x space and more: \s+
Daniel Petrov
3,495 PointsDaniel Petrov
3,495 PointsThanks! What about 2 x space? Is it matched by \s? In this case, it is probably safer to always use \s. Unless you are 100% sure there will be strictly one space.