Python 3 Programming Tutorial – Regular Expressions / Regex with re

///Python 3 Programming Tutorial – Regular Expressions / Regex with re

Python 3 Programming Tutorial – Regular Expressions / Regex with re

FavoriteLoadingAdd to favorites

Regular expressions are used to sift through text-based data to find things. Regular expressions express a pattern of data that is to be located. Regex is its own language, and is basically the same no matter what programming language you are using with it.

In Python 3, the module to use regular expressions is re, and it must be imported to use regular expressions.

Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/

Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M

http://seaofbtc.com
http://sentdex.com
http://hkinsley.com

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6

By |2017-05-01T12:20:09+00:00April 26th, 2017|Programming Video Tutorials, Python Video Tutorials|50 Comments

50 Comments

  1. Kevin Suriel April 26, 2017 at 10:30 pm - Reply

    Smart dude!

  2. Patrick Glynn April 26, 2017 at 10:31 pm - Reply

    Thank you for this dude. I’ve been watching a lot of your videos. You’ve been such a help!

  3. chamillion reptil April 26, 2017 at 10:31 pm - Reply

    God bless you!

  4. Samatbek Osmonov April 26, 2017 at 10:34 pm - Reply

    Awesome tutorial! Thank you so much!

  5. PETAJOULE543 April 26, 2017 at 10:34 pm - Reply

    how grandfather can be 5 year older?

  6. Parag Mantri April 26, 2017 at 10:35 pm - Reply

    At 15:00, why do we need to tell python it is regular expression by using r in (). Aren’t we already doing it by using ‘re’ in re.findall?

  7. Jushkhun Juret April 26, 2017 at 10:37 pm - Reply

    Thank you so much, it’s so helpful!!!

  8. harvir74 April 26, 2017 at 10:38 pm - Reply

    dude you should write a book you’r explanations make so much more sense than all the python books i have. koodos.

  9. adv4000 April 26, 2017 at 10:38 pm - Reply

    thanx but need more examples

  10. Mohamed Gabr April 26, 2017 at 10:39 pm - Reply

    what is the best reference for regular expression brother? 🙂

  11. Олександр Зозуля April 26, 2017 at 10:40 pm - Reply

    Making a dictionary(c) from two lists(a, b): c = dict(zip(a, b))

  12. Robert Koronka April 26, 2017 at 10:40 pm - Reply

    At 5:43 when you added that colon for consistency’s sake, I knew you I should subscribe.

  13. Mariam Jibrin April 26, 2017 at 10:41 pm - Reply

    sorry could you make a tutorial of this searching for html tags please

  14. TheMateusjunior April 26, 2017 at 10:43 pm - Reply

    hi , you first statement is d{1,3} , but how do you obtain the 97 ages ?

  15. BASS BOOSTED OFFICIAL April 26, 2017 at 10:43 pm - Reply
  16. phillip mabry April 26, 2017 at 10:44 pm - Reply

    Thanks for this.

  17. Naveenraj Kali April 26, 2017 at 10:49 pm - Reply

    OSM! nice explanation.

    Can you Pl give more examples on RegExp ?

  18. danilo mitrovic April 26, 2017 at 10:49 pm - Reply

    dude,list comprehension

  19. Gyanender Singhle April 26, 2017 at 10:53 pm - Reply

    u r superb best source to learn python

  20. Oliver Li April 26, 2017 at 10:53 pm - Reply

    i like your sentdex a lot, and im planning to use it when i get my hands on the US stock market, so when i heard the age always follows the name (14:00), i want to suggest you to improve.

    What about
    "The 35-year-old Jack is a Pythoner."?

  21. Yi Sheng Siow April 26, 2017 at 10:54 pm - Reply

    breaking it down into IDENTIFIERS and MODIFIERS is so helpful for my understanding! thanks!

  22. unbreakable footage April 26, 2017 at 10:55 pm - Reply

    RRRREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

  23. AJ AL April 26, 2017 at 10:57 pm - Reply

    which software you use to record the monitor ???

  24. Wanderson Santos Costa April 26, 2017 at 10:57 pm - Reply

    I am sold, subscribed! print(‘You just save my live!!’)

  25. NARENDRA WALAWALKAR April 26, 2017 at 10:57 pm - Reply

    [’15’, ’20’, ’97’, ‘102’]
    []
    I am getting this output though I have written the same program…
    import re
    exampleString = ”’
    Jessica is 15 years old, daniel is 20 years old.
    Edward is 97, and his grandfather, oscar, is 102.
    ”’
    ages = re.findall(r’ d{1,3}’, exampleString)
    names = re.findall(r'[A-Z][a-z]’, exampleString)
    print (ages)
    print(names)
    please tell me if there is any silly mistake that I’m doing

  26. Guitar Guitar April 26, 2017 at 10:58 pm - Reply

    ages = re.findall(r’d{1,3}’,exampleString) question: why we have to put a ‘r’ before ”d{1,3}”?

  27. Luis Medina April 26, 2017 at 10:59 pm - Reply

    Thanks for this Python basics tutorials!

  28. ruyl2 April 26, 2017 at 11:00 pm - Reply

    zip(names, ages)

  29. Giovanni Gianni April 26, 2017 at 11:02 pm - Reply

    >>> ageDict = {a:b for a,b in zip(names,ages)}
    >>> ageDict
    {‘Oscar’: ‘102’, ‘Edward’: ’97’, ‘Daniel’: ’27’, ‘Jessica’: ’15’}

  30. Martin Fülöp April 26, 2017 at 11:02 pm - Reply

    18:09
    or just use enumerate()

  31. Xingyu Bian April 26, 2017 at 11:02 pm - Reply

    Your videos are awesome!

  32. Tobias Fan April 26, 2017 at 11:04 pm - Reply

    Thanks for the tutorials, homes!

  33. Alfred Garrett April 26, 2017 at 11:12 pm - Reply

    Great Tutorial! really cleared up regular expressions for me!

  34. Charlie Brown April 26, 2017 at 11:13 pm - Reply

    Hello… Please how do I contact you

  35. Honey Khangura April 26, 2017 at 11:13 pm - Reply

    Most of your tutorials are completely to the point, Why you have went so far rather than showing some more and more practical examples? Sorry if my words are bit edgy but I really love rest of your tutorials specially Python for Finance!

  36. Sidahmed Tlili April 26, 2017 at 11:14 pm - Reply

    thanks

  37. 李李里 April 26, 2017 at 11:15 pm - Reply

    after searching and learning python for several months now, you are so far the best teacher, thanks so much.

  38. D. Refaeli April 26, 2017 at 11:15 pm - Reply

    Awesome video man – thanks a lot!

  39. mithridil April 26, 2017 at 11:16 pm - Reply

    I have this code:

    prefixes = re.findall(r’^(un|con|in|pre)?(un|con|in|pre)?(un|con|in|pre)?(.*)$’,unpredictable )

    It means that in a string (word) we have more than one prefixes un-, pre-….. i want to use a regex lookahead to every one of them so my code understands that there should be a word (.*) after the 3d parenthesis (un|con|in|pre), there should be a prefix (from 3d parenthesis) after the 2nd parenthesis and so on…

    I want to do this cause i want to check if the last one is a real word from a wordlist… i will replace (.*) with a word from a wordlist. For example if i give the word "redeconstruct" i want to make my code understand that there should be a word struct from the wordlist first, then at its left one of the prefixes in 3d parenthesis, then at its left one in 2nd and so on…
    If i give another example like "undo" i want a result like this: [" "," ","un","do"].
    Could you help me please? Cause in every tutorial the lookbehind and lookahead are so basic and i have intentionally fixed width errors :/

  40. Santosh Paudel April 26, 2017 at 11:17 pm - Reply

    You literally make my programming experience much easier. Sentdex, can you please do a tutorial on sqalchemy ? No matter how many books I read or documentations, I have never been able to understand that thing. Youtube doesn’t have good tutorials on that either. I would really appreciate if you could help us learn sqalchemy.

  41. Unknown Name April 26, 2017 at 11:19 pm - Reply

    You are awesome
    Till now i learned Python for hobby
    Now i seriously thinking to become professional Pyhton Programmer like U… 🙂

  42. Ryan Lindskog April 26, 2017 at 11:21 pm - Reply

    Man, you’re awesome. I never took the time to learn regex, finally just got around to it. Thank you for the help.

    Here is what I did:

    import re

    exampleString = ”’
    Jessica is 15 years old, and Daniel is 27 years old.
    Edward is 97, and his grandfather, Oscar is 102.
    ”’

    people = re.findall(r"([A-Z][a-z]+)[a-zs]*(d{1,3})", exampleString)
    people_dict = {name: age for name, age in people}
    print(people_dict)

  43. Caspa April 26, 2017 at 11:21 pm - Reply

    Man, Edward and Oscar gotta be brothers with them close ages lol.

  44. Greg F April 26, 2017 at 11:22 pm - Reply

    Great RE intro and a _very_ practical demonstration! Thanks …

  45. Varshap Walia April 26, 2017 at 11:23 pm - Reply

    I don’t know why i play your videos at 1.25 speed and it still feels normal.

  46. Amal Shehu April 26, 2017 at 11:24 pm - Reply

    Informative

  47. Alexander Storozhenko April 26, 2017 at 11:24 pm - Reply

    I am not really sure what parsing is .Can you please explain that.
    thanks

  48. Sawai Maheshwari April 26, 2017 at 11:25 pm - Reply

    Excellent Explain……..Thank You….

  49. Rohit Chawla April 26, 2017 at 11:28 pm - Reply

    Hey, its great to see your videos. I was trying to print all the strings which contain [aeiourstln] and one more letter in any order. Could you please help me in ‘re’ expression for the same. Thanks

  50. Francisco Javier Vargas Morales April 26, 2017 at 11:29 pm - Reply

    Excellent tutorial !!!

Leave A Comment

*