Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python re return index of match

import re

target_string = "Emma is a basketball player who was born on June 17, 1993"
# match method with pattern and target string using match()
result = re.match(r"w{10}", target_string)
# printing  match
print("Match: ", result) # None

# using search()
result = re.search(r"w{10}", target_string)
# printing match
print("Match value: ", result.group()) # basketball
print("Match starts at", result.start()) # index 10
Source by pynative.com #
 
PREVIOUS NEXT
Tagged: #python #return #index #match
ADD COMMENT
Topic
Name
4+6 =