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

peter keves
peter keves
6,854 Points

why did we use \t although we did'nt before

why did we use \t although we did'nt before at the end of each group

2 Answers

Hi , if you notice the names.txt the name, email, phone number, job and twitter are separated by tabs and not spaces. Basically you search for the whole pattern since all of them are separated by tabs ,to get them all you need to add \t at the end of each group. So basically what groups do is to just select the the part you need from the matched pattern. For Ex: string = 'Hello World'(tab inbetween them) to get both the words my pattern would be '[\w]+\t[\w]+' but this will give me Hello\tWorld, to get just Hello and World we use groups ([\w]+)\t([\w]+) now this will give me (Hello,World) a tuple for the whole pattern and each item in the tuple corresponds to a group. So basically group tells python what parts of a pattern to be taken after a pattern is matched.

Max Hirsh
Max Hirsh
16,773 Points

It's been a while since I took the regular expressions course, but I think "\t" is a symbol for cutting trailing whitespace. I think this tells the regex interpreter/python to expect a space or tab after a particular pattern of characters, but to not include it as part of what is returned.