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 Negation

Does findall() also include newline character by default?

I got curious while watching this video and tried a regular expression as follow

print(re.findall(r'@[Kenneth Lomax](https://teamtreehouse.com/kennethlomax) [-.?\d\w]*[^gov\t]\b',data))

It return the following list: ['@teamtreehouse.com', '@kennethlove\n', '@teamtreehouse.com', '@camelot.co.uk', '@norr botten.co.se', '@sverik', '@killerrabbit.com', '@teamtreehouse.com', '@ryancarson\n', ' @tardis.co.uk', '@example.com', '@example\n', '@us.', '@potus44\n', '@teamtreehouse.com ', '@chalkers\n', '@empire.', '@darthvader\n', '@spain.']
1.My first question why do many of the entries have a newline character also coming in the match when my pattern does not have a newline character in the characterclass/set. 2.In the video why is \t being used does findall() match tabs eventhough they are not mentioned in the pattern.

Alexander Davison :Request you inputs for my query.

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points
  1. \b picks up whitespace 2. you are excluding anything ending with tabs along with anything ending with g, o or v with the ^gov\t clause. so i don't think it's findall, i think it's the use of \b that's picking up the newlines.

I removed \b from the pattern and tried but I got an identical output as before.