Find all occurrences of a text element (in case it appears multiple times).
Parameters
Name
Type
Description
Default
text
str
A text string to search for elements within it.
required
elements
str | list[str]
A string to lookup in text or a list of strings to find in text
required
Returns
Name
Type
Description
List[TextSpan]
List of TextSpan objects with start/end positions
Examples
>>> text ="Hello world! This is a test find the a world in here.">>> loc = txt_locate_all(text, "world")>>> loc[TextSpan(text='world', start=6, end=11), TextSpan(text='world', start=39, end=44)]>>> loc = txt_locate_all(text, "notinthetext")>>> loc[]>>> loc = txt_locate_all(text, ["test", "a", "world"])>>> loc[TextSpan(text='test', start=23, end=27), TextSpan(text='a', start=21, end=22), TextSpan(text='a', start=37, end=38), TextSpan(text='world', start=6, end=11), TextSpan(text='world', start=39, end=44)]