import re
# Target String
target_string = "Emma is a baseball player who was born on June 17, 1993."
# find substring 'ball'
result = re.search(r"ball", target_string)
# Print matching substring
print(result.group())
# output 'ball'
# find exact word/substring surrounded by word boundary
result = re.search(r"\bball\b", target_string)
if result:
print(result)
# output None
# find word 'player'
result = re.search(r"\bplayer\b", target_string)
print(result.group())
# output 'player'
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter