I know how to use python to report exact match in a string:
import re
word='hello,_hello,"hello'
re.findall('\\bhello\\b',word)
['hello', 'hello']
How do I report the indices of the exact matches? (in this case, 0 and 14)
I know how to use python to report exact match in a string:
import re
word='hello,_hello,"hello'
re.findall('\\bhello\\b',word)
['hello', 'hello']
How do I report the indices of the exact matches? (in this case, 0 and 14)
Use finditer:
[(g.start(), g.group()) for g in re.finditer('\\b(hello)\\b',word)]
# [(0, 'hello'), (14, 'hello')]
instead use word.find('hello',x)
word = 'hello,_hello,"hello'
tmp = 0
index = []
for i in range(len(word)):
tmp = word.find('hello', tmp)
if tmp >= 0:
index.append(tmp)
tmp += 1