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 Negation

Why use a set to match an exact sequence of characters?

You are using [^gov] to negate e-mail addresses from the "gov" domain. But this set would also negate 'g', 'o', 'v', 'vog', 'ggg', etc. Similarly for matching "Treehouse" in a previous example. Isn't this a confusing (mis)use of sets?

Or Ohev-Zion
Or Ohev-Zion
22,277 Points

That's correct, although for that specific excercise what quite enough. FYI, there is another way, to ommit only 'gov' strings by use of () like so: re.match('(^[\w\d.]+@)gov?([ยท\w]+)', string_to_match) Now what this code does, is return results that answer the query inside the () only. So only gov strings after @ sign are omitted. This for example could return if it exists in the string to match - @vog

Hi @Or, I know there are more restrictive (I would even say "more correct") ways of doing this. My point is that the lectures suggest that this is a good way to do it and I imagine it will lead to students writing bugs. Maybe a health warning is needed.