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 trialWelby Obeng
20,340 PointsCan someone explain the + well for me
In search = r"[-\w\d+.]+@[-\w\d+]+" why do we need to add + in the set and outside of the set. What are we saying when we add it and not add it
3 Answers
KAZUYA NAKAJIMA
8,851 PointsI thought + sign inside first [] is just intended to catch doctor's email address which has '+' inside it.
However, + sign outside [] means 'match any character inside [], once or more'
I'm not confident but it seems right...
ericb2
11,429 Pointsexample:
>>> text = "2+4 you+me"
# []+ searches for 1 or more of whatever is inside []
>>> re.findall(r'\b[\w]+\b', text)
['2', '4', 'you', 'me']
# [+] searches for '+' in text
>>> re.findall(r'\b[\w+]\b', text)
['2', '+', '4', '+']
# both inside and out
>>> re.findall(r'\b[\w+]+\b', text)
['2+4', 'you+me']
Trevor Currie
9,289 PointsInside your square brackets, you're defining the group of allowed characters in the string that you're looking for, i.e. dashes (-), word characters (\w), numbers (\d), plus signs (+) and points (.). Outside the square brackets, when you use the plus sign, you're saying that there can be any number of any of the group of allowed characters in that string.
It's a small difference, but an important one.
Welby Obeng
20,340 PointsCan you please explain with examples. What do you mean allow in any group of characters?
William Li
Courses Plus Student 26,868 PointsWelby, I suggest that you re-watch the video, Kenneth Love covers that during the lectures with examples.
Welby Obeng
20,340 PointsWilliam I tried that already...thank you
I want to know the difference in the + in the set vs the + outside the set
David Axelrod
36,073 PointsDavid Axelrod
36,073 PointsThis is my understanding as well!