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 Name Groups

what is the point of the "\t" chars after each group??

for the last video on groups

2 Answers

\t is a tab character. Tab characters and spaces are related, because they both are whitespace (spaces, tabs, newlines, verical newlines, etc.) It is used for separation usually, but the character can be handy in programming when you want to "indent" code. In Python, it usually is required to indent code, but in more flexible languages like JavaScript or Ruby, you don't need to indent but it's nice to. Here's an example of code that's not indented:

for x in range(10):
print(x)

This would cause an error in Python. However, if you indent it used the "tab" character:

for x in range(10):
    print(x)

It should work. I'm actually not using four spaces, I'm using a tab character that looks like four spaces. If you select the character, it will select it whole, rather than selecting spaces individually. Kenneth had put tabs between names, phone numbers, email addresses, jobs, etc., so that's why he's including tabs at the end of everything.

I hope you understand now! :)

Good luck! ~Alex

Note: Updated "Kenneth used space between names, phone numbers, etc." to "Kenneth used tabs between names, phone number,s etc." See that update! :)

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Christine;

The \t is an escape character which represents and is interpreted as a "tab".

Ken

Thank you, I understand that. I should have been more specific with my question sorry. I meant to ask why is it okay for him to match groups with just the tab char between them instead of r'(<group>),\s(<group>)' as it is in the text? When I tried doing r'(<group>)\t(<group>)' on the code challenge it didn't work. what makes it work in his context...