Python Tutorial: re Module – How to Write and Match Regular Expressions (Regex)

///Python Tutorial: re Module – How to Write and Match Regular Expressions (Regex)

Python Tutorial: re Module – How to Write and Match Regular Expressions (Regex)

FavoriteLoadingAdd to favorites

In this Python Programming Tutorial, we will be learning how to read, write, and match regular expressions with the re module. Regular expressions are extremely useful for matching common patterns of text such as email addresses, phone numbers, URLs, etc. Learning how to do this within Python will allow us to quickly parse files and text for the information we need. Let’s get started…

The code from this video can be found at:

Python String Slicing Tutorial:

Python Files Tutorial:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –

#Python

source

By |2019-08-17T22:07:31+00:00August 17th, 2019|Python Video Tutorials|22 Comments

22 Comments

  1. Balaji Rajokkiyam August 17, 2019 at 10:07 pm - Reply

    @6:42 looks like in version (3.6) we no need to escape special characters if you are searching it as part of a string.

  2. Mina sMorgul August 17, 2019 at 10:07 pm - Reply

    I'm 2 minutes in, and have learned more than in past 3 days. Keep on the good work!

  3. deepjyot singh kapoor August 17, 2019 at 10:07 pm - Reply

    Awesome tutorial !!

  4. Minecraft Storage August 17, 2019 at 10:07 pm - Reply

    Thanks that video was extrimely helpful

  5. komal kakade August 17, 2019 at 10:07 pm - Reply

    I am trying to write a regex pattern for key value pair, which is like "abc" : ["Hcs", "kod Hnj", "Dfr"],. I need to find this pattern in a html document for web scraping, could you please help me how to do this?

  6. Chris Keo August 17, 2019 at 10:07 pm - Reply

    What a public service!

  7. UrSoMeanBoss August 17, 2019 at 10:07 pm - Reply

    Useful tool for RE debugging and a visual representation of RE search pattern logic
    https://www.debuggex.com/

  8. GSS Infotech August 17, 2019 at 10:07 pm - Reply

    This is the best RE tutorial I ever came across. Thank you so much Corey for your effort making this tutorial.

  9. ben andrew777 August 17, 2019 at 10:07 pm - Reply

    you are always awesome !!!!!!!!!!!!!!!!

  10. ANGELO WATTERS R. August 17, 2019 at 10:07 pm - Reply

    confusing.

  11. T S August 17, 2019 at 10:07 pm - Reply

    Brilliant

  12. Lunatite August 17, 2019 at 10:07 pm - Reply

    Thank you ! This is a awesome/easily understandable tutorial since I'm learning Regular Expressions for the first time.

  13. Alejandro Rodriguez August 17, 2019 at 10:07 pm - Reply

    flawless

  14. Justic H August 17, 2019 at 10:07 pm - Reply

    import re

    #(for beginning code)

    text_to_search ="""

    abcdefghijklmnopqrstuvwxyz

    ABCDEFGHIJKLMNOPQRSTUVWXYZ

    123456789

    Ha HaHa

    Metacharacters (Need to be escaped):

    . ^ $ * + ? { } [ ] | ( )

    coreyms.com

    321-555-4321

    123.555.1234

    Mr. Schafer

    Mr Smith

    Ms Davis

    Mrs. Robinson

    Mr. T

    """

    sentence='Start a sentence and then bring it to an end'

    pattern = re.compile(r'abc')

  15. dragonking696 August 17, 2019 at 10:07 pm - Reply

    I have used regex for a while but not in Python. Using re in python and trying to just display the match seemed like a chore to figure out. Finally found group(0) but was not sure what this was grouping. Your explanation in this video was so very helpful and gave me the info I was looking for. Thank you!

  16. Thuy Doan August 17, 2019 at 10:07 pm - Reply

    Corey, Thank you so much for making this video. Very easy to understand. You are the "MAN!!!" .

  17. Niranjan Tamhane August 17, 2019 at 10:07 pm - Reply

    Best Video For Regex!!

  18. Surajit Chakraborty August 17, 2019 at 10:07 pm - Reply

    Hi Corey, Fantastic Video. I had a query. I am on Python 3.6.8 and with regards to the example that talks about the regular expression : re.compile(r'https?://(www.)?(w+)(.w+)'), I am not able to obtain any output with match.group(1) or match.group(2) or match.group(2). Any help appreciated

  19. Suvantola S August 17, 2019 at 10:07 pm - Reply

    solid video!

  20. sourin banik August 17, 2019 at 10:07 pm - Reply

    sir please make a video on pandas

  21. CodeTheGlobe August 17, 2019 at 10:07 pm - Reply

    How do we add these searches into a separate list?

  22. CodeTheGlobe August 17, 2019 at 10:07 pm - Reply

    U should do a course on udemy..

Leave A Comment

*