Пример:
Код: Выделить всё
long_string = 'this is a t`es"t. Does the test work?'
small_string = "test"
chars_to_ignore = ['"', '`']
print(find_occurrences(long_string, small_string))
- — это начальный и конечный индекс t`es"t в long_string,
Код: Выделить всё
(10, 16) - — это начальный и конечный индекс теста в long_string.
Код: Выделить всё
(27, 31)
Код: Выделить всё
import re
long_string = 'this is a t`es"t. Does the test work?'
small_string = "test"
matches = []
[matches.append((m.start(), m.end())) for m in re.finditer(small_string, long_string)]
print(matches)
Подробнее здесь: https://stackoverflow.com/questions/787 ... some-chara