René's URL Explorer Experiment


Title: Work With a Token (Video) – Real Python

Open Graph Title: Work With a Token – Real Python

Description: The regular expression for support_tom could actually look very similar. When you put in \[support_tom\], you can see that [support_tom] with the square brackets is selected in your test string. However, this is a good point where we could be a bit…

Open Graph Description: The regular expression for support_tom could actually look very similar. When you put in \[support_tom\], you can see that [support_tom] with the square brackets is selected in your test string. However, this is a good point where we could be a bit…

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

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
  {
    "@context": "https://schema.org",
    "@type": "VideoObject",
    "name": "Work With a Token",
    "description": "The regular expression for support_tom could actually look very similar. When you put in \u005C[support_tom\u005C], you can see that [support_tom] with the square brackets is selected in your test string. However, this is a good point where we could be a bit…",
    "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": "PT2M4S",
    
    "potentialAction": {
      "@type": "SeekToAction",
      "target": "https://realpython.com/lessons/replace-string-python-token/#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-token/
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-token/
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-token%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-token/#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-token/#transcript
Discussion (2)https://realpython.com/lessons/replace-string-python-token/#discussion
00:00https://realpython.com/lessons/replace-string-python-token/#t=0.59
The regular expression for support_tom could actually look very similar.https://realpython.com/lessons/replace-string-python-token/#t=0.59
When you put in \[support_tom\],https://realpython.com/lessons/replace-string-python-token/#t=5.48
you can see that [support_tom] with the square brackets is selected in your testhttps://realpython.com/lessons/replace-string-python-token/#t=11.27
string. However,https://realpython.com/lessons/replace-string-python-token/#t=14.97
this is a good point where we could be a bit more flexible and actually leveragehttps://realpython.com/lessons/replace-string-python-token/#t=16.35
the powers of regular expressions. What if there are multiple support agents?https://realpython.com/lessons/replace-string-python-token/#t=20.72
00:25https://realpython.com/lessons/replace-string-python-token/#t=25.14
So you don’t want to look specifically for Tom,https://realpython.com/lessons/replace-string-python-token/#t=25.14
but basically for any support agent.https://realpython.com/lessons/replace-string-python-token/#t=28.02
00:32https://realpython.com/lessons/replace-string-python-token/#t=32.7
For this, you can use a so-called token,https://realpython.com/lessons/replace-string-python-token/#t=32.7
and the token that you want to use is the w.https://realpython.com/lessons/replace-string-python-token/#t=35.1
But since the w now should have a special meaning,https://realpython.com/lessons/replace-string-python-token/#t=38.94
it’s not enough to just put a w into it. Instead,https://realpython.com/lessons/replace-string-python-token/#t=42.23
you need to put the escape character (\) in front of it. Again,https://realpython.com/lessons/replace-string-python-token/#t=46.22
00:50https://realpython.com/lessons/replace-string-python-token/#t=50.58
once you put a backslash in front of the w,https://realpython.com/lessons/replace-string-python-token/#t=50.58
you can see regex101 marks the regular expression inputhttps://realpython.com/lessons/replace-string-python-token/#t=53.01
string a bit different. However, the way that it’s written right now,https://realpython.com/lessons/replace-string-python-token/#t=57.75
your regular expression doesn’t find any match in the test string.https://realpython.com/lessons/replace-string-python-token/#t=61.84
01:06https://realpython.com/lessons/replace-string-python-token/#t=66.23
So, the next thing that you need to do is to put an asterisk (*).https://realpython.com/lessons/replace-string-python-token/#t=66.23
01:11https://realpython.com/lessons/replace-string-python-token/#t=71.37
What exactly happened there? With an asterisk,https://realpython.com/lessons/replace-string-python-token/#t=71.37
you say that the token that was used before should match zero or multiplehttps://realpython.com/lessons/replace-string-python-token/#t=74.12
times.https://realpython.com/lessons/replace-string-python-token/#t=79.1
So you look for a string that’s in square brackets and says supporthttps://realpython.com/lessons/replace-string-python-token/#t=80.12
and any alphanumerical character. That could be a letter, a number,https://realpython.com/lessons/replace-string-python-token/#t=85.24
or the underscore. In your text below,https://realpython.com/lessons/replace-string-python-token/#t=89.4
there are always more characters before the closing square bracket,https://realpython.com/lessons/replace-string-python-token/#t=92.19
and that’s why when you add the asterisk, now the [support_tom] username in squarehttps://realpython.com/lessons/replace-string-python-token/#t=96.2
brackets matches. And again,https://realpython.com/lessons/replace-string-python-token/#t=100.78
the cool thing is even if it would be [support_tommy],https://realpython.com/lessons/replace-string-python-token/#t=102.52
you can see that the test string is still highlighted,https://realpython.com/lessons/replace-string-python-token/#t=107.04
so your regular expression pattern still finds the username.https://realpython.com/lessons/replace-string-python-token/#t=109.12
01:53https://realpython.com/lessons/replace-string-python-token/#t=113.56
That’s cool. Okay,https://realpython.com/lessons/replace-string-python-token/#t=113.56
but let’s leave it with support_tom and copy the regular expression inputhttps://realpython.com/lessons/replace-string-python-token/#t=114.78
and save it in text file because you will need it in a moment.https://realpython.com/lessons/replace-string-python-token/#t=119.64
Jan. 19, 2025https://realpython.com/lessons/replace-string-python-token/#comment-d668c91e-ef18-49b5-9e01-e14f36c7931a
Jan. 20, 2025https://realpython.com/lessons/replace-string-python-token/#comment-a8644b2d-6021-4b16-b4af-4b0b0e374576
Become a Memberhttps://realpython.com/account/join/
https://realpython.com/lessons/replace-string-python-john-doe/
Overviewhttps://realpython.com/courses/replace-string-python/
https://realpython.com/lessons/replace-string-python-case-insensitive/
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.