Tags: python regular expressions regex re module python re python regular expressions python re module python regex python regex module regular expression re python tutorial python 3.6 corey schafer programming tutorials python programming match patterns software engineering
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:
https://github.com/CoreyMSchafer/code_snippets/tree/master/Python-Regular-Expressions
Python String Slicing Tutorial:
https://youtu.be/ajrtAuDg3yw
Python Files Tutorial:
https://youtu.be/Uh2ebFW8OYM
✅ Support My Channel Through Patreon:
https://www.patreon.com/coreyms
✅ Become a Channel Member:
https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join
✅ One-Time Contribution Through PayPal:
https://goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
http://a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
https://www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - http://coreyms.com/
My Second Channel - https://www.youtube.com/c/coreymschafer
Facebook - https://www.facebook.com/CoreyMSchafer
Twitter - https://twitter.com/CoreyMSchafer
Instagram - https://www.instagram.com/coreymschafer/
#Python
or
Question
I watch lots of videos related to programming and so far I haven't seen anyone upload high quality material as consistently as you do. There's a lot of content out there nowadays but most just scratches the surface. Your videos live up to the famous quote by Einstein "Everything should be made as simple as possible, but not simpler". :)
I didn't quite grasp the function of some of the regex methods used. For example, Corey said the Compile method allows us to separate patterns into a variable, which can then be used to perform multiple searches... I couldn't find much documentation on regex methods online to clarify what that means.
Can anyone suggest specific resources to learn more about them? Thanks in advance!
Wait, why was 'abc' not indexed as 0-3? Does the string index in this case start at 1??
Thank You Corey for this amazing lesson. I experimented with the code and realized that we can just use our reg expressions without putting them up as a raw strings, and it worked. But when doing the pattern.sub('\2\3', urls) part, it din't worked. But when I kept it as a raw string, it worked. So my question is, Why are we using our reg exs as raw string ? Do we always have to do that?
It's really a great explanation!
However you didn't mention "greedy" and group escaping.
The output I am getting looks like <_sre.SRE_Match object at 0x1002b48b8>. Can someone indicate what I have to do to get a more meaningful output as shown in the video? In particular I am not getting the span.
This was what I really wanted, i searched for python RE all over Youtube, but none of those videos were like this! thanks corey, you are the best ptython teacher :)
i wish i had the money to contribute to your channel. m trying to get a job.
Hey Corey, you mentioned that adding 'r' before the re pattern indicates to Python that backslashes should not be interpreted with any special meaning. But then you mentioned that metacharacters need to be escaped with a backslash and in the example you provided (r'\.') the re pattern was preceded by an 'r'.
I guess it's implied, but just to be crystal clear- are metacharacters the exception to this rule regarding 'r'?
Thanks Corey for this awesome video.
Every time i search for any python topic, you are my first recommendation and you never failed to amuse me.
Hey any plans about web scraping in Selenium.
thanks