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.

Python Regular Expressions in Python Introduction to Regular Expressions Groups

vikas pal
vikas pal
10,413 Points

what the difference?

Please see the video first before giving the answer .In the video he uses this '^' and this'$' .So what difference it make in the code and the output in the shell is still same nothing is different.so why we used it and using multiline flag no difference is found in the output and please also tell me what \t do.

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Vikas;

These symbols, ^ and $ are anchors, or atomic zero-width assertions, and specify a position in the string where a match much occur.

The ^ anchor indicates that the match must occur at the beginning of the string or line. While the $ anchor indicates that the match must occur at the end of the string or line, or before \n at the end of the string or line.

For example, ^\d{3} will match "901" in "901-331-" since it starts at the beginning of the string, while \d{3}$ would match "331" in the same string since it matches at the end of the string.

Hope that helps and happy coding,
Ken

vikas pal
vikas pal
10,413 Points

thank you so much you easily cleared by doubts.i send a message to you on twitter.please start talk to me so i can ask question from you and easily get my answers.Ken Alger