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

Daniel Petrov
Daniel Petrov
3,495 Points

Is 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
Steven Parker
231,269 Points

:point_right: 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.

Daniel Petrov
Daniel Petrov
3,495 Points

Thanks! 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.

Alx Ki
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alx Ki
Python Web Development Techdegree Graduate 14,822 Points

Daniel 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+