Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Regular Expressions in Python Introduction to Regular Expressions Negation

Naivedya Bansal
Naivedya Bansal
5,483 Points

[^gov\t]

Not sure whether this is ignoring any of the characters g,o,v or all the characters . Also why is the \t so important here , if I remove it the output changes radically and it picks up a lot of unuseful data. also how do u ensure that these characers are ignore after the '.' symbol and not before it?

Naivedya Bansal
Naivedya Bansal
5,483 Points

also another thing that is really confusing me is how is a word boundary identified? If we remove the \b in the beginning of the regex we created the string "@kennethlove" is also being picked up. I didn't get how this is working.

1 Answer

So as it stands this regex [^gov\t] ignores anyone one of those the characters g, o, v, or a tab. Not being able to see all the code it is hard to remeber why \t is important in this case but I'm guessing it is because you are trying to skip along to the next word ignoring the tab in-between.

The \b defines a word boundary as a white space or non-word character (which could be at the beginning of the string or the end).

A great place to test out your regex, and get an explanation of why it works is regex101. I'm pretty enamored with it. You can even have it show you the python specific version of the code which is nice at times.