René's URL Explorer Experiment


Title: Append a Quantifier (Video) – Real Python

Open Graph Title: Append a Quantifier – Real Python

Description: Since timestamps are always the same length, you can use a handy trick here and add a quantifier to your regular expression. Quantifiers are set in curly braces ({}). The moment you add a number into the quantifier, the regular expression looks for…

Open Graph Description: Since timestamps are always the same length, you can use a handy trick here and add a quantifier to your regular expression. Quantifiers are set in curly braces ({}). The moment you add a number into the quantifier, the regular expression looks for…

Opengraph URL: https://realpython.com/lessons/replace-string-python-quantifier/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
  {
    "@context": "https://schema.org",
    "@type": "VideoObject",
    "name": "Append a Quantifier",
    "description": "Since timestamps are always the same length, you can use a handy trick here and add a quantifier to your regular expression. Quantifiers are set in curly braces ({}). The moment you add a number into the quantifier, the regular expression looks for…",
    "thumbnailUrl": ["https://files.realpython.com/media/How-to-Replace-Parts-of-a-String-in-Python_Watermarked.a70c83972fa6.jpg"],
    "uploadDate": "2023-08-22T14:00:00+00:00",
    "duration": "PT2M18S",
    
    "potentialAction": {
      "@type": "SeekToAction",
      "target": "https://realpython.com/lessons/replace-string-python-quantifier/#t={seek_to_second_number}",
      "startOffset-input": "required name=seek_to_second_number"
    }
  }
  

authorReal Python
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/How-to-Replace-Parts-of-a-String-in-Python_Watermarked.a70c83972fa6.jpg
og:imagehttps://files.realpython.com/media/How-to-Replace-Parts-of-a-String-in-Python_Watermarked.a70c83972fa6.jpg
twitter:creator@realpython
og:typevideo.episode

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/lessons/replace-string-python-quantifier/
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/quizzes/
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Code Mentor →BetaPersonalized code assistance & learning toolshttps://realpython.com/mentor/
Unlock All Content →https://realpython.com/account/join/
More https://realpython.com/lessons/replace-string-python-quantifier/
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Contributorhttps://realpython.com/jobs/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?next=%2Flessons%2Freplace-string-python-quantifier%2F
Unlock This Lessonhttps://realpython.com/account/join/?utm_source=rp_lesson&utm_content=replace-string-python
Unlock This Lessonhttps://realpython.com/account/join/?utm_source=rp_lesson&utm_content=replace-string-python
https://realpython.com/courses/replace-string-python/#team
Replacing a String in Pythonhttps://realpython.com/courses/replace-string-python/
Philipp Acsanyhttps://realpython.com/courses/replace-string-python/#team
Recommended Tutorialhttps://realpython.com/replace-string-python/
Course Slides (.pdf)https://realpython.com/courses/replace-string-python/downloads/replace-string-python-slides/
Sample Code (.zip)https://realpython.com/courses/replace-string-python/downloads/replace-string-python-code/
Ask a Questionhttps://realpython.com/lessons/replace-string-python-quantifier/#discussion
https://realpython.com/feedback/survey/course/replace-string-python/liked/?from=lesson-title
https://realpython.com/feedback/survey/course/replace-string-python/disliked/?from=lesson-title
Transcripthttps://realpython.com/lessons/replace-string-python-quantifier/#transcript
Discussionhttps://realpython.com/lessons/replace-string-python-quantifier/#discussion
00:00https://realpython.com/lessons/replace-string-python-quantifier/#t=0.58
Since timestamps are always the same length,https://realpython.com/lessons/replace-string-python-quantifier/#t=0.58
you can use a handy trick here and add a quantifier to your regularhttps://realpython.com/lessons/replace-string-python-quantifier/#t=3.55
expression. Quantifiers are set in curly braces ({}).https://realpython.com/lessons/replace-string-python-quantifier/#t=7.9399999999999995
00:13https://realpython.com/lessons/replace-string-python-quantifier/#t=13.29
The moment you add a number into the quantifier,https://realpython.com/lessons/replace-string-python-quantifier/#t=13.29
the regular expression looks for the pattern that you had before exactly onehttps://realpython.com/lessons/replace-string-python-quantifier/#t=16.33
time. So that’s not different than what you did before.https://realpython.com/lessons/replace-string-python-quantifier/#t=20.47
00:25https://realpython.com/lessons/replace-string-python-quantifier/#t=25.17
The moment you add a 2 into it,https://realpython.com/lessons/replace-string-python-quantifier/#t=25.17
something’s changed, and it almost seems that you are getting the fullhttps://realpython.com/lessons/replace-string-python-quantifier/#t=27.74
timestamp. However, the 0 at the end is not matched. And if you look closely,https://realpython.com/lessons/replace-string-python-quantifier/#t=32.27
the visualizer also shows you two different colors.https://realpython.com/lessons/replace-string-python-quantifier/#t=37.65
00:41https://realpython.com/lessons/replace-string-python-quantifier/#t=41.85
One is a bit of a lighter blue, and the other one is a bit of a darker blue,https://realpython.com/lessons/replace-string-python-quantifier/#t=41.85
and that means the regular expression matches two found tokens from thehttps://realpython.com/lessons/replace-string-python-quantifier/#t=46.17
expression before. So it’s like the 20 from 2022https://realpython.com/lessons/replace-string-python-quantifier/#t=50.71
and then the 22 and then the -0, and then the 8-, and so on.https://realpython.com/lessons/replace-string-python-quantifier/#t=55.21
00:59https://realpython.com/lessons/replace-string-python-quantifier/#t=59.93
So it always matches a pair of two.https://realpython.com/lessons/replace-string-python-quantifier/#t=59.93
So what you can do now is count the characters that the timestamp contains,https://realpython.com/lessons/replace-string-python-quantifier/#t=62.65
and that’s 25. So once you put in 25 here,https://realpython.com/lessons/replace-string-python-quantifier/#t=68.47
then you can see that your full timestamp is matched.https://realpython.com/lessons/replace-string-python-quantifier/#t=73.0
01:16https://realpython.com/lessons/replace-string-python-quantifier/#t=76.79
Now the match of the timestamp has the same color,https://realpython.com/lessons/replace-string-python-quantifier/#t=76.79
so that means the entity of the timestamp matches your regularhttps://realpython.com/lessons/replace-string-python-quantifier/#t=79.63
expression. Or to be more precise,https://realpython.com/lessons/replace-string-python-quantifier/#t=83.98
that your regular expression now matches the timestamp that you have in yourhttps://realpython.com/lessons/replace-string-python-quantifier/#t=86.36
test string.https://realpython.com/lessons/replace-string-python-quantifier/#t=89.77
01:31https://realpython.com/lessons/replace-string-python-quantifier/#t=91.64
You can even make one more adjustment to this regular expression,https://realpython.com/lessons/replace-string-python-quantifier/#t=91.64
and that’s putting a space on the front of your regular expression becausehttps://realpython.com/lessons/replace-string-python-quantifier/#t=95.76
that way, you will also match the space before the timestamp.https://realpython.com/lessons/replace-string-python-quantifier/#t=100.49
01:44https://realpython.com/lessons/replace-string-python-quantifier/#t=104.48
The 25 quantifier stays the same because it only refers to the token that ishttps://realpython.com/lessons/replace-string-python-quantifier/#t=104.48
found before,https://realpython.com/lessons/replace-string-python-quantifier/#t=109.3
and that’s your character set that you’re looking for in timestamp.https://realpython.com/lessons/replace-string-python-quantifier/#t=109.72
01:53https://realpython.com/lessons/replace-string-python-quantifier/#t=113.36
And the space is literally the space that your regular expression matcheshttps://realpython.com/lessons/replace-string-python-quantifier/#t=113.36
now. You can see the space that I’m talking about visualized as thishttps://realpython.com/lessons/replace-string-python-quantifier/#t=117.64
dot between the username and the timestamp.https://realpython.com/lessons/replace-string-python-quantifier/#t=122.58
02:06https://realpython.com/lessons/replace-string-python-quantifier/#t=126.14
So this will be helpful when you work with the regular expression in the nexthttps://realpython.com/lessons/replace-string-python-quantifier/#t=126.14
lesson. Just like before,https://realpython.com/lessons/replace-string-python-quantifier/#t=129.48
copy this regular expression and don’t forget the space at the beginning andhttps://realpython.com/lessons/replace-string-python-quantifier/#t=132.01
paste it into a text file.https://realpython.com/lessons/replace-string-python-quantifier/#t=135.66
Become a Memberhttps://realpython.com/account/join/
https://realpython.com/lessons/replace-string-python-character-set/
Overviewhttps://realpython.com/courses/replace-string-python/
https://realpython.com/lessons/replace-string-python-regex-patterns/
Replace a String in Python (Overview) 01:48 https://realpython.com/videos/replace-string-python-overview/
Investigate the Transcript 02:02 https://realpython.com/videos/replace-string-python-transcript/
Replace a String With .replace() 03:06 https://realpython.com/videos/replace-string-python-method/
Chain the .replace() Method 02:33 https://realpython.com/lessons/replace-string-python-chain/
Set Up Multiple Replacement Rules 04:14 https://realpython.com/lessons/replace-string-python-multiple-rules/
Use a Regex Visualizer 01:59 https://realpython.com/lessons/replace-string-python-regex-visualizer/
Find John Doe 02:14 https://realpython.com/lessons/replace-string-python-john-doe/
Work With a Token 02:04 https://realpython.com/lessons/replace-string-python-token/
Be Case-Insensitive 02:08 https://realpython.com/lessons/replace-string-python-case-insensitive/
Look for a Character Set 01:55 https://realpython.com/lessons/replace-string-python-character-set/
Append a Quantifier 02:18 https://realpython.com/lessons/replace-string-python-quantifier/
Recap Your Regex Patterns 00:13 https://realpython.com/lessons/replace-string-python-regex-patterns/
Get to Know re.sub() 01:09 https://realpython.com/lessons/replace-string-python-resub-intro/
Use re.sub() 05:11 https://realpython.com/lessons/replace-string-python-resub/
Replace a String in Python (Summary) 02:08 https://realpython.com/lessons/replace-string-python-summary/
Privacy Policyhttps://realpython.com/privacy-policy/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.