Regular Expressions in Python || Python Tutorial || Learn Python Programming

Sdílet
Vložit
  • čas přidán 22. 07. 2024
  • 𝙎𝙩𝙖𝙮 𝙞𝙣 𝙩𝙝𝙚 𝙡𝙤𝙤𝙥 𝙄𝙉𝙁𝙄𝙉𝙄𝙏𝙀𝙇𝙔: snu.socratica.com/python
    Regular Expressions (regex for short) is a way to search for patterns in strings. Python provides the re module to assist you in your efforts to search through strings. Maybe you want to find names in a database that satisfy certain conditions. But before you charge right in and start throwing regular expressions around, you need to learn the correct syntax.
    In this video, you’ll learn how to compose regular expressions using such cryptic symbols as the caret (^), dollar sign ($), various backslashes (\d, \s, \w), and more. And just wait ‘til you see what happens when you start combining them into a powerful combo search expression.
    We also introduce such concepts as quantifiers so you can see how many times you get a match. Match, that’s another handy function, along with fullmatch. You’ll learn how useful it can be to create groups to name certain parts of a regex. We could go on, but it makes more sense for you to watch the video and take notes. Then share it with a friend and have them take notes. Then you can compare your notes and see if you are in agreement.
    We were able to bring you this video thanks to our generous Kickstarter backers! Find their names hidden (okay, not very hidden) in the video!
    Find our programming playlists here:
    Python: bit.ly/PythonSocratica
    SQL: bit.ly/SQL_Socratica
    Subscribe to Socratica + bell for notifications:
    bit.ly/SocraticaSubscribe
    ⧓⧓⧓⧓⧓
    We recommend:
    How to Be a Great Student
    ebook: amzn.to/2Lh3XSP
    Paperback: amzn.to/3t5jeH3
    Kindle Unlimited (read free): amzn.to/3atr8TJ
    Python Cookbook, 3rd edition
    amzn.to/3jprjX2
    The Mythical Man Month - Essays on Software Engineering & Project Management
    amzn.to/3hPn8Dd
    ⧓⧓⧓⧓⧓
    Join this channel to get access to perks:
    / @socratica
    Support Socratica on Patreon:
    / socratica
    Python instructor: Ulka Simone Mohanty (@ulkam on Twitter)
    Written & Produced by Michael Harrison
    Edited by Megi Shuke and Michael Harrison
    #Python #RegularExpressions #regex

Komentáře • 158

  • @HarshitDaftary
    @HarshitDaftary Před rokem +128

    Great to see python videos again 😊

  • @patricksweeney6334
    @patricksweeney6334 Před rokem +32

    I absolutely love Ulka's ability to deliver the dry sense of humor that permeates these videos. "To use regular expressions with python, import the 're' module. After hours of research, we were unable to find what 're' stands for."

  • @LandOfSigh
    @LandOfSigh Před rokem +31

    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems.

  • @Socratica
    @Socratica  Před rokem +29

    𝙎𝙩𝙖𝙮 𝙞𝙣 𝙩𝙝𝙚 𝙡𝙤𝙤𝙥 𝙄𝙉𝙁𝙄𝙉𝙄𝙏𝙀𝙇𝙔: snu.socratica.com/python
    Quick Note: In regular expressions, a dot . matches ANY character. So our URL regex, https?://w{3}.\w+ etc works, but could be greatly improved if we replace the . pattern with \.
    The \. matches only the period.

  • @massimo6767
    @massimo6767 Před rokem +36

    Hi! I was a first year student when i used to watch your python tutorials.
    Now i am a full-time Data Eng. and seeing your videos again makes me kinda nostalgic (in a positive way).
    Thanks so much for your work, your videos helped me a lot during my first steps ❤

    • @Socratica
      @Socratica  Před rokem +8

      We love hearing about where your journey is taking you! Thanks for including us. 💜🦉

    • @EternalVoice11
      @EternalVoice11 Před rokem +3

      Thank you Socrotica for these beautiful video tutorials

  • @nonominox
    @nonominox Před rokem +14

    Perfect timing, we're just starting with re in our Python class!

    • @linghung9797
      @linghung9797 Před 10 měsíci

      How is it going? I’m starting mine this week

  • @Allen-by6ci
    @Allen-by6ci Před rokem +7

    Ulka has perfected her character. More of her teaching everything. She's awesome

  • @jagadishgospat2548
    @jagadishgospat2548 Před rokem +12

    I didn't expect it to be this easy to understand, thanks guys.

  • @martinus9755
    @martinus9755 Před rokem +6

    Great to see another one of these videos. They're clear, concise and the format is really fun.

  • @bassbacke
    @bassbacke Před rokem +8

    I thought I had some idea about regular expressions but now I know there's so much more to the re module.
    Thanks for inspiring us to dive deeper into the re module.

  • @davidawakim5473
    @davidawakim5473 Před rokem +1

    Love that Socratica is back! Y'all make the best educational videos I've seen in a long time, just binged the abstract algebra playlist and now hoping into more learning! Thank you!!

  • @sarundayo
    @sarundayo Před rokem +5

    Glad these series is still alive and well :DD

  • @aiforyounow
    @aiforyounow Před rokem +9

    Forever my favorite channel

  • @HexenzirkelZuluhed
    @HexenzirkelZuluhed Před rokem +26

    Great video. Note however that in the last examples with the URLs, you are using '.' to look for a literal dot in the URL. A single dot in a pattern matches any character. If you want to look for a literal dot, you need to use '\.'. Also, Python supports verbose regular expressions, that allow comments inside the code.

  • @MrPioneer7
    @MrPioneer7 Před rokem

    Welcome back! Really happy to see your long videos again since you are the best teacher I've ever had

  • @EuphoricRaccoon
    @EuphoricRaccoon Před rokem

    Seeing an upload of a Python tutorial with Ulka from Socratica once again after all this time made me incredibly happy.
    Seriously, all of these are a bloody gem

  • @brunosantos3672
    @brunosantos3672 Před rokem +2

    I'm happy to see a new Python video here!

  • @BrianStDenis-pj1tq
    @BrianStDenis-pj1tq Před rokem

    I love Socratica so much. The writing, presentation and subject matter are awesome.

  • @ehouston3
    @ehouston3 Před rokem +1

    ❤Thank you for creating more Python videos! Theses are THE BEST! You ladies are awesome, thanks for making knowledge accessible.

  • @gamorales
    @gamorales Před rokem +2

    RegEx is one of the most beautiful things that exists. Python make RegEx really easy and simple to use. 😍

  • @chrisj21b
    @chrisj21b Před rokem +2

    Great video, we need more of this!

  • @dewaynescott5114
    @dewaynescott5114 Před rokem

    These videos rock. Have been leveraging them to learn Python. Thank you.

  • @JANSENM9
    @JANSENM9 Před rokem

    This is the reason I am a Socratica patreon. Thank you - there will never be too many of these!

    • @Socratica
      @Socratica  Před rokem

      Amazing. Thank you for helping us make these videos possible! 💜🦉

  • @pthube
    @pthube Před rokem

    It is great to see you back..

  • @hellionaires_sniping
    @hellionaires_sniping Před rokem

    By far the best channel i know for learning python. Thanks for everything!!! Unfortunately i wasted a lot of time watching confusing video´s from other python developers.

  • @SuperYtc1
    @SuperYtc1 Před rokem

    I'm glad to see this series back. I said only this week in a video that I was sad they were discontinued. I hope you do more.

    • @SuperYtc1
      @SuperYtc1 Před rokem

      Also would be good if you did some JavaScript in this style.

  • @ydydydyd146
    @ydydydyd146 Před rokem

    I really liked this video! It taught me everything I needed to know quickly and it was incredibly funny. You've earned my sub!

  • @d0m2288
    @d0m2288 Před 2 měsíci

    Awesome resource, as usual. I'm debugging an API and traced the issue back to some bad regular expression in one of the controllers.

  • @shivamjaiswal5825
    @shivamjaiswal5825 Před rokem +2

    Love Python videos from Socratica

  • @user-dc9od8tn2r
    @user-dc9od8tn2r Před 7 měsíci

    Great videos ever seen ,Your are making the videos as more understanding the concepts .This is best tutorials in youtube everseen .Thanks for the tutorial and do more .

  • @jimparsons6803
    @jimparsons6803 Před rokem

    Thanks. Love these videos. Always a treat!

  • @NikitaNair
    @NikitaNair Před 3 měsíci +1

    Such an amazing video... Very easily explained and effective for learning

  • @amit12000
    @amit12000 Před rokem

    Great video on regex and nice see new video after long time

  • @shinrafahell
    @shinrafahell Před rokem +1

    Awesome tutorial, I love the way you teach.

  • @WendimuSitotaw
    @WendimuSitotaw Před rokem +1

    Love the python videos here at Socratica!

  • @angladephil
    @angladephil Před rokem +1

    Nice to see you again !

  • @yonaguska2050
    @yonaguska2050 Před rokem

    I’ve missed her videos, she’s very entertaining.

  • @chefboyrdee1
    @chefboyrdee1 Před rokem

    I needed this ! thank you

  • @SatyaDurgapavaniGanta
    @SatyaDurgapavaniGanta Před 4 měsíci

    Finally I found the best video in CZcams

  • @ncmathsadist
    @ncmathsadist Před 24 dny

    Nice regex intro. Excellent!

  • @waltertross3581
    @waltertross3581 Před rokem

    I'm glad you correctly pronounced regex (not like rejex) , and used the correct plural of index (indices). It took me a bit, though, to realize you were ironical about being unable to find the meaning of re.

  • @klamentyne5991
    @klamentyne5991 Před rokem

    Yay...she's back! xx

  • @foustcor
    @foustcor Před rokem +1

    Yay! Python's back!

  • @zeitgenosse
    @zeitgenosse Před rokem +2

    12:01 This regex will also match https followed by colon, followed by two forward slashes, followed by wwwsocraticaorg. The first dot would match the s, the backslash w+ would match ocratic and the last dot would match the a. To circumvent this, you need to escape the dot with a backslash.

  • @pippobraco8501
    @pippobraco8501 Před rokem +1

    you're the best teacher

  • @flarone
    @flarone Před rokem +1

    This series is great.

  • @BrianStDenis-pj1tq
    @BrianStDenis-pj1tq Před rokem

    Regular expressions go deep (really deep) - as in they are complicated and nuanced. This is an overview. The "corrections" explained in the comments are correct but maybe more useful for the next video on regex. I was going to suggest a video on regex module vs re... but that isn't a "learning" video, its an "advanced use case" video. Thanks Socratica!

  • @markocska94
    @markocska94 Před rokem

    I am so happy to see my favourite AI tutor back ❤

  • @iceiceisaac
    @iceiceisaac Před rokem

    Love this channel

  • @pile333
    @pile333 Před rokem +2

    Interesting! 👏

  • @rantalbott6963
    @rantalbott6963 Před rokem

    Add me to the people praising the "performance" (deadpan delivery and subtle humor) that makes these videos engaging and even entertaining. But I especially want to praise the basic design of splitting them into narrow topics and going into just the right depth.
    I've learned over a dozen languages over the last 50+ years, so what I'm looking for as I learn Python is not the "This is a bit. This is a byte. This is a loop" basics I learned decades ago. What I need is is answers like "How are lists different from C arrays?" and "How is regex matching different from Awk or Perl?". Last week I needed to do some input validation, and regexes were the right tool. A few minutes with this video showed me the Python way to do it without needing to wade through a lot of non-regex material.
    You're doing great. Thanks.

  • @dhamodharang7665
    @dhamodharang7665 Před 9 měsíci

    Good to understand 😊

  • @adithyays731
    @adithyays731 Před 6 měsíci

    omg ur sense of humour is awesome

  • @IIAyogu
    @IIAyogu Před rokem

    A great content as always!

  • @freckhard
    @freckhard Před rokem +10

    Hey there great video and finally some python again! I have an annotation at 12:12 to make: while the dot technically matches the dot in regular expression it stands for "any character at all" (including the dot 🙂). If you really need a dot (and not a hyphen or anything else) we would need to escape that as well with \. 👏 Happy Holidays Socratica!

    • @Socratica
      @Socratica  Před rokem +5

      Excellent point! We should have spent some time talking about the . pattern since it's so common. We'll pin a comment to make sure people understand the difference between . \.

    • @Flashxyz123
      @Flashxyz123 Před rokem

      @@Socratica you never pinned this guys comment

  • @anesumukanya8811
    @anesumukanya8811 Před rokem +1

    love ur work Ulka you are a star. Please do a video to demystify the use of the super() function!!!

  • @thomas_m3092
    @thomas_m3092 Před rokem

    I love your videos. Straight to the point, not like humans who waste a lot of time.
    Could you make some videos about GUI programming in Python?

  • @angeloj.willems4362
    @angeloj.willems4362 Před rokem

    Welcome back. We missed you!
    To save time and oxygen,... Classic!
    Something happens,... and then they profit. Hilarious!

  • @benatakaan613
    @benatakaan613 Před rokem +1

    ❤❤❤ More Python videos please!

  • @peter8261
    @peter8261 Před 9 měsíci

    Her videos are like a Red Alert cinematic. I absolutely love them.

  • @JC-ds1jh
    @JC-ds1jh Před rokem +1

    Thank you I love your videos. I use them in my cyber security class to help my students with Python

    • @Socratica
      @Socratica  Před rokem +2

      We're so thrilled you're sharing our videos with your students. Thank you for letting us know!

  • @abhideepsingh4484
    @abhideepsingh4484 Před rokem

    after a long time!

  • @DENIESCAT
    @DENIESCAT Před rokem

    Nice tutorial and nice video

  • @volbla
    @volbla Před rokem +3

    One sequence i find handy is \h. It matches whitespaces, just like \s, but \s includes newline characters whereas \h doesn't. Usually when i search through text i want to keep to one line at a time.
    edit: Actually disregard that. Apparently that sequence is not in python's regex module :(

  • @dwla16
    @dwla16 Před rokem

    You turn the lesson into fun activity I love you for that❤ very unique way of teaching do you have any Java course

  • @muhammedfahimkpfahim8606
    @muhammedfahimkpfahim8606 Před 11 měsíci

    good explantion thankyou

  • @lawrencedoliveiro9104

    Here’s a handy one: “\b” for matching word boundaries. For example, using “\bi\b” to search through code for the variable “i” without matching parts of every single word containing the letter “i”.

  • @bobert13581
    @bobert13581 Před 8 měsíci

    thanks for saving some of my oxygen with this efficient learnings

  • @nwoDekaTsyawlA
    @nwoDekaTsyawlA Před rokem +8

    For some reason, my brain always forgets which of ^ and $ is the correct one to use in each case. Now I will always remember the ^farmer$.

  • @jpt13913
    @jpt13913 Před rokem

    Enjoy examples They help Make it clear

  • @OP-do7rt
    @OP-do7rt Před rokem +1

    pls teach full python we love you

  • @maximillianquaife-larsen3799

    Thank you

  • @NipkowDisk
    @NipkowDisk Před rokem

    I think regular expressions are like oysters: you either love them or hate them. Personally, I love them as they really helped me to extract data from one file format and convert it into another for usage in a land surveying statistical analysis program :)

  • @GrypV
    @GrypV Před rokem +1

    Thanks!

    • @Socratica
      @Socratica  Před rokem

      Thank you so much for your kind support!! 💜🦉

  • @nonominox
    @nonominox Před rokem +2

    @Socratica which editor/theme do you use?

  • @soufianta8374
    @soufianta8374 Před 5 měsíci

    After months of research, I’m still unable to find what “re” stands for !! Love your videos !! Keep going

  • @XxKingfisherxX
    @XxKingfisherxX Před rokem

    i think you meant letters when you are saying words!! you contents are awesome

  • @kirbymarchbarcena
    @kirbymarchbarcena Před rokem +1

    Her expressions are so priceless

  • @finnbin1
    @finnbin1 Před rokem

    WOW ...me at 5.32.... how cool is that???? cool video...

  • @hasanyousef492
    @hasanyousef492 Před rokem

    great video and presentation, what is the software you used to make such great presentation?

  • @RichPenn
    @RichPenn Před rokem +1

    Well done as always, glad to see a new one. Richard K5ANR

  • @calebthiem3150
    @calebthiem3150 Před rokem +1

    Thanks

    • @Socratica
      @Socratica  Před rokem

      Goodness, thank you so much for your support! 💜🦉

  • @scottbiggs8894
    @scottbiggs8894 Před 8 měsíci

    I deeply applaud this video, thank you! But could you update this for python 3? A host of regex no longer functions as specified in this video.

  • @victorcercasin
    @victorcercasin Před rokem

    "They start with carrots, something happens, and then they profit". That shit in 2x speed is hilarious

  • @lack76
    @lack76 Před rokem +1

    Man I have spent quite a bit of time on regex, but as soon as I turn away from it for 5 seconds the knowledge floats away.

  • @oliver2671
    @oliver2671 Před rokem +2

    Q: ChatGPT, please extract two consecutive vowels by using regex in python from following string: "Francois".
    A:....
    Simple code problems do not need to be understood anymore, great!

    • @ithinkthereforeitalk935
      @ithinkthereforeitalk935 Před rokem

      Exactly my thoughts. The revolution's coming but not too many people in the comment section are aware of this😉

    • @cuszco
      @cuszco Před rokem +2

      I don't think "do not need to be understood anymore" is the right approach to this time saving marvel, though.

    • @oliver2671
      @oliver2671 Před rokem +1

      @@cuszco Take it with a slight hint of sarcasm

    • @cuszco
      @cuszco Před rokem

      @@oliver2671 That's actually a good idea. Thanks :D

    • @dieterweik6858
      @dieterweik6858 Před rokem +1

      Who knows. Perhaps "Hand-coded" will become a thing. Just like "Hand-Made". Then again... maybe not.

  • @StevenHancz
    @StevenHancz Před rokem +2

    Correction @6:55 the regex is looking for strings that contain 'C' followed by word characters not string shat start with 'C' character. The regex needs the ^ prefix to make it search for sting starting with 'C'.

    • @Socratica
      @Socratica  Před rokem +2

      We were actually using this regex to look for any sequence of characters that starts with C, not strings that start with C themselves. Here's a case where some emphasis would have been a good idea, especially since so many of our examples used the ^ pattern.

  • @kwrifles
    @kwrifles Před rokem +1

    Regex is very powerful but I've always found it easy but confusing

  • @xReeco
    @xReeco Před rokem

    best

  • @Flashxyz123
    @Flashxyz123 Před rokem

    doesnt the RE module stand for regular expretions?

  • @fdama
    @fdama Před rokem

    7:29 How did the regex match "HappyCodingRobot"? It starts with H not C.

  • @SpeaksYourWord
    @SpeaksYourWord Před 7 měsíci

    re stands for regular expressions?

  • @XxKingfisherxX
    @XxKingfisherxX Před rokem

    what does "?=.*" mean in regex? Expecting detail lesson.

  • @EpicRSvids
    @EpicRSvids Před rokem

    ❤❤❤

  • @Flashxyz123
    @Flashxyz123 Před rokem

    Is Re module built in tho?

  • @Lilina3456
    @Lilina3456 Před 11 měsíci

    RE stands for Regular Expressions 5:00

  • @dwla16
    @dwla16 Před rokem

    ❤❤❤❤❤❤❤

  • @danycordero5308
    @danycordero5308 Před 3 měsíci

    Hi Socratica, Please be informed that the examples using char (code 710)" ^ " shown in this video do not match with the objetive ?? can you explain the reason? , for example the expression /^\w{7}$ / does not find any character.

  • @kyoujinko
    @kyoujinko Před 5 měsíci

    ;0Thank you, I just wanted to know what REGEX was. Other videos were getting very complicated into the process of it, and all I wanted was to know what it was

  • @lszujo73
    @lszujo73 Před 7 měsíci

    weird but I guess it's good information😀