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 The Basics

Error`first` doesn't seem to be a regex match. Works in Preview first = r'Four' print(re.match(first, data))

I'm stuck on challenge task 4/5 with the error first doesn't seem to be a regex match. It does appear to work in the Preview though. first returns "Four" What's am I doing wrong this time?

import re

file_object = open("basics.txt", encoding="utf-8")
data = file_object.read()

first = r'Four'
re.match(first, data)

4 Answers

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

You need to assign the re.match() to the first variable.

first = re.match(...)

you are doing re.match(first, data) but where is it going to end up at present? i.e. accessable?

I first tried

print(re.match(first, data)) 

...but that didn't work either. Is that what you mean? Making it accessible via print?

Thanks! I get it now!