Answers for "regex how to find all matches"

0

regex find a word index of all matches

import re
sentence = input("Give me a sentence ")
word = input("What word would you like to find ")
for match in re.finditer(word, sentence):
    print (match.start(), match.end())
Posted by: Guest on September-11-2020
0

regex match exact string

you want to achieve a case insensitive match for the word "rocket" 
surrounded by non-alphanumeric characters. A regex that would work would be:

W*((?i)rocket(?-i))W*
Posted by: Guest on August-23-2020
3

re.match() python

import re

pattern = '^a...s$'
test_string = 'abyss'
result = re.match(pattern, test_string)

if result:
  print("Search successful.")
else:
  print("Search unsuccessful.")
Posted by: Guest on July-17-2020

Code answers related to "regex how to find all matches"

Python Answers by Framework

Browse Popular Code Answers by Language