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

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.