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.
nicole lumpkinCourses Plus Student 5,328 Points
Using the + character at the end of a set
This has really been bugging me. It was my understanding that the + character when used after a set means any character within the set must appear at lease once. My question is why does the following pattern match my email variable(defined below) even though the '+' character, amongst others, is not present in the string?
email = 'firstname.lastname@example.org' print(re.findall(r'[-\w\d+.]+@[-\w\d.]+', email, re.I)) >>>['email@example.com']
Why does this work(match)?? There are no digits, hyphens, or plus characters in 'email'.
Steven Parker221,070 Points
The plus character itself is not actually part of the allowed/required set.
The regex "
[-\w\d.]+" means "at least one hyphen, "word character", digit, or period". The digit (\d) metacharacter is actually not needed here since a "word character" (\w) can be any alpha-numeric character or