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

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 มิ.ย. 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

ความคิดเห็น • 158

  • @HarshitDaftary
    @HarshitDaftary ปีที่แล้ว +128

    Great to see python videos again 😊

    • @matthewwithum8372
      @matthewwithum8372 ปีที่แล้ว +1

      💯

    • @5cyndi
      @5cyndi ปีที่แล้ว +2

      I know right? 💜 I love the straightforward but humorous presentation.

  • @patricksweeney6334
    @patricksweeney6334 ปีที่แล้ว +26

    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."

    • @crownstupid
      @crownstupid ปีที่แล้ว +2

      something happens, and then they profit

    • @fredsmith6324
      @fredsmith6324 ปีที่แล้ว

      uhuh uhuh uhuh...

  • @LandOfSigh
    @LandOfSigh ปีที่แล้ว +18

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

  • @massimo6767
    @massimo6767 ปีที่แล้ว +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  ปีที่แล้ว +8

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

    • @EternalVoice11
      @EternalVoice11 ปีที่แล้ว +3

      Thank you Socrotica for these beautiful video tutorials

  • @Socratica
    @Socratica  ปีที่แล้ว +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.

  • @Allen-by6ci
    @Allen-by6ci ปีที่แล้ว +7

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

  • @nonominox
    @nonominox ปีที่แล้ว +14

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

    • @linghung9797
      @linghung9797 9 หลายเดือนก่อน

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

  • @jagadishgospat2548
    @jagadishgospat2548 ปีที่แล้ว +12

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

  • @bassbacke
    @bassbacke ปีที่แล้ว +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.

  • @martinus9755
    @martinus9755 ปีที่แล้ว +6

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

  • @HexenzirkelZuluhed
    @HexenzirkelZuluhed ปีที่แล้ว +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.

    • @alexrubio9507
      @alexrubio9507 9 หลายเดือนก่อน

      very good observation there

  • @davidawakim5473
    @davidawakim5473 ปีที่แล้ว +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!!

  • @aiforyounow
    @aiforyounow ปีที่แล้ว +9

    Forever my favorite channel

  • @sarundayo
    @sarundayo ปีที่แล้ว +5

    Glad these series is still alive and well :DD

  • @MrPioneer7
    @MrPioneer7 ปีที่แล้ว

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

  • @5cyndi
    @5cyndi ปีที่แล้ว

    I love the dry wit of these Python tutorials 💜 I’ve been enjoying them for years and glad to see this new one! It’s so relevant. One can never have too many regexes. Well… maybe. But with this great presentation I am refreshing my skills and getting a chuckle at the same time. Cheers!

  • @EuphoricRaccoon
    @EuphoricRaccoon ปีที่แล้ว

    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

  • @BrianStDenis-pj1tq
    @BrianStDenis-pj1tq ปีที่แล้ว

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

  • @brunosantos3672
    @brunosantos3672 ปีที่แล้ว +2

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

  • @ehouston3
    @ehouston3 ปีที่แล้ว +1

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

  • @hellionaires_sniping
    @hellionaires_sniping ปีที่แล้ว

    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.

  • @chrisj21b
    @chrisj21b ปีที่แล้ว +2

    Great video, we need more of this!

  • @JANSENM9
    @JANSENM9 ปีที่แล้ว

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

    • @Socratica
      @Socratica  ปีที่แล้ว

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

  • @dewaynescott5114
    @dewaynescott5114 ปีที่แล้ว

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

  • @shivamjaiswal5825
    @shivamjaiswal5825 ปีที่แล้ว +2

    Love Python videos from Socratica

  • @gamorales
    @gamorales ปีที่แล้ว +2

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

  • @shinrafahell
    @shinrafahell ปีที่แล้ว +1

    Awesome tutorial, I love the way you teach.

  • @ydydydyd146
    @ydydydyd146 ปีที่แล้ว

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

  • @pthube
    @pthube ปีที่แล้ว

    It is great to see you back..

  • @NikitaNair
    @NikitaNair 2 หลายเดือนก่อน +1

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

  • @angladephil
    @angladephil ปีที่แล้ว +1

    Nice to see you again !

  • @WendimuSitotaw
    @WendimuSitotaw ปีที่แล้ว +1

    Love the python videos here at Socratica!

  • @SuperYtc1
    @SuperYtc1 ปีที่แล้ว

    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 ปีที่แล้ว

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

  • @jimparsons6803
    @jimparsons6803 ปีที่แล้ว

    Thanks. Love these videos. Always a treat!

  • @user-dc9od8tn2r
    @user-dc9od8tn2r 5 หลายเดือนก่อน

    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 .

  • @amit12000
    @amit12000 ปีที่แล้ว

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

  • @SatyaDurgapavaniGanta
    @SatyaDurgapavaniGanta 3 หลายเดือนก่อน

    Finally I found the best video in TH-cam

  • @markocska94
    @markocska94 ปีที่แล้ว

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

  • @pile333
    @pile333 ปีที่แล้ว +2

    Interesting! 👏

  • @peter8261
    @peter8261 7 หลายเดือนก่อน

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

  • @benatakaan613
    @benatakaan613 ปีที่แล้ว +1

    ❤❤❤ More Python videos please!

  • @waltertross3581
    @waltertross3581 ปีที่แล้ว

    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.

  • @pippobraco8501
    @pippobraco8501 ปีที่แล้ว +1

    you're the best teacher

  • @foustcor
    @foustcor ปีที่แล้ว +1

    Yay! Python's back!

  • @flarone
    @flarone ปีที่แล้ว +1

    This series is great.

  • @klamentyne5991
    @klamentyne5991 ปีที่แล้ว

    Yay...she's back! xx

  • @yonaguska2050
    @yonaguska2050 ปีที่แล้ว

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

  • @d0m2288
    @d0m2288 22 วันที่ผ่านมา

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

  • @zeitgenosse
    @zeitgenosse ปีที่แล้ว +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.

  • @chefboyrdee1
    @chefboyrdee1 ปีที่แล้ว

    I needed this ! thank you

  • @BrianStDenis-pj1tq
    @BrianStDenis-pj1tq ปีที่แล้ว

    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!

  • @IIAyogu
    @IIAyogu ปีที่แล้ว

    A great content as always!

  • @rantalbott6963
    @rantalbott6963 ปีที่แล้ว

    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.

  • @iceiceisaac
    @iceiceisaac ปีที่แล้ว

    Love this channel

  • @nonominox
    @nonominox ปีที่แล้ว +2

    @Socratica which editor/theme do you use?

  • @dhamodharang7665
    @dhamodharang7665 7 หลายเดือนก่อน

    Good to understand 😊

  • @anesumukanya8811
    @anesumukanya8811 ปีที่แล้ว +1

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

  • @angeloj.willems4362
    @angeloj.willems4362 ปีที่แล้ว

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

  • @thomas_m3092
    @thomas_m3092 ปีที่แล้ว

    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?

  • @JC-ds1jh
    @JC-ds1jh ปีที่แล้ว +1

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

    • @Socratica
      @Socratica  ปีที่แล้ว +2

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

  • @freckhard
    @freckhard ปีที่แล้ว +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  ปีที่แล้ว +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 ปีที่แล้ว

      @@Socratica you never pinned this guys comment

  • @adithyays731
    @adithyays731 4 หลายเดือนก่อน

    omg ur sense of humour is awesome

  • @abhideepsingh4484
    @abhideepsingh4484 ปีที่แล้ว

    after a long time!

  • @DENIESCAT
    @DENIESCAT ปีที่แล้ว

    Nice tutorial and nice video

  • @hasanyousef492
    @hasanyousef492 ปีที่แล้ว

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

  • @volbla
    @volbla ปีที่แล้ว +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 :(

  • @nwoDekaTsyawlA
    @nwoDekaTsyawlA ปีที่แล้ว +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$.

  • @muhammedfahimkpfahim8606
    @muhammedfahimkpfahim8606 10 หลายเดือนก่อน

    good explantion thankyou

  • @dwla16
    @dwla16 ปีที่แล้ว

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

  • @bobert13581
    @bobert13581 7 หลายเดือนก่อน

    thanks for saving some of my oxygen with this efficient learnings

  • @lawrencedoliveiro9104
    @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”.

  • @soufianta8374
    @soufianta8374 4 หลายเดือนก่อน

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

  • @OP-do7rt
    @OP-do7rt ปีที่แล้ว +1

    pls teach full python we love you

  • @XxKingfisherxX
    @XxKingfisherxX ปีที่แล้ว

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

  • @scottbiggs8894
    @scottbiggs8894 7 หลายเดือนก่อน

    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.

  • @NipkowDisk
    @NipkowDisk ปีที่แล้ว

    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 :)

  • @maximillianquaife-larsen3799
    @maximillianquaife-larsen3799 3 หลายเดือนก่อน

    Thank you

  • @GrypV
    @GrypV ปีที่แล้ว +1

    Thanks!

    • @Socratica
      @Socratica  ปีที่แล้ว

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

  • @oliver2671
    @oliver2671 ปีที่แล้ว +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 ปีที่แล้ว

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

    • @cuszco
      @cuszco ปีที่แล้ว +2

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

    • @oliver2671
      @oliver2671 ปีที่แล้ว +1

      @@cuszco Take it with a slight hint of sarcasm

    • @cuszco
      @cuszco ปีที่แล้ว

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

    • @dieterweik6858
      @dieterweik6858 ปีที่แล้ว +1

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

  • @jpt13913
    @jpt13913 ปีที่แล้ว

    Enjoy examples They help Make it clear

  • @Flashxyz123
    @Flashxyz123 ปีที่แล้ว

    doesnt the RE module stand for regular expretions?

  • @finnbin1
    @finnbin1 ปีที่แล้ว

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

  • @RichPenn
    @RichPenn ปีที่แล้ว +1

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

  • @SpeaksYourWord
    @SpeaksYourWord 6 หลายเดือนก่อน

    re stands for regular expressions?

  • @fdama
    @fdama ปีที่แล้ว

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

  • @lack76
    @lack76 ปีที่แล้ว +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.

  • @XxKingfisherxX
    @XxKingfisherxX ปีที่แล้ว

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

  • @kirbymarchbarcena
    @kirbymarchbarcena ปีที่แล้ว +1

    Her expressions are so priceless

  • @calebthiem3150
    @calebthiem3150 ปีที่แล้ว +1

    Thanks

    • @Socratica
      @Socratica  ปีที่แล้ว

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

  • @kwrifles
    @kwrifles ปีที่แล้ว +1

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

  • @victorcercasin
    @victorcercasin 11 หลายเดือนก่อน

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

  • @StevenHancz
    @StevenHancz ปีที่แล้ว +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  ปีที่แล้ว +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.

  • @danycordero5308
    @danycordero5308 หลายเดือนก่อน

    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.

  • @Flashxyz123
    @Flashxyz123 ปีที่แล้ว

    Is Re module built in tho?

  • @xReeco
    @xReeco ปีที่แล้ว

    best

  • @EpicRSvids
    @EpicRSvids ปีที่แล้ว

    ❤❤❤

  • @timarmstrong8765
    @timarmstrong8765 ปีที่แล้ว

    Wait is this new series for Python?

  • @Lilina3456
    @Lilina3456 9 หลายเดือนก่อน

    RE stands for Regular Expressions 5:00

  • @kyoujinko
    @kyoujinko 3 หลายเดือนก่อน

    ;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

  • @dwla16
    @dwla16 ปีที่แล้ว

    ❤❤❤❤❤❤❤