Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python search string for word

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"ball", target_string)
if result:
    print(result)
# output None

# find word 'player'
result = re.search(r"player", target_string)
print(result.group())
# output 'player'
Source by pynative.com #
 
PREVIOUS NEXT
Tagged: #python #search #string #word
ADD COMMENT
Topic
Name
2+4 =