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 trialharveylim
1,870 PointsAre strings even compatible with re.match?
I know Kenneth showed how to open and read a file, but can you do the same with a string?
import re
def first_number(string):
return re.match('\d', string)
1 Answer
Kenneth Love
Treehouse Guest TeacherYep. re.match()
just wants a string to match against. If you remember, when we were using it to search a file, we were really searching a string we made from the file.
harveylim
1,870 Pointsharveylim
1,870 PointsThe only Escape hatch that matches this is \w, but it matches 'a' instead because the number isn't the first character.