I know how to search for a word and split a string by it. Example:
s = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua'
r = re.compile('(elit)')
r.split(s)
# => ['Lorem ipsum dolor sit amet, consectetur adipisicing ', 'elit', ', sed do eiusmod tempor incididunt ut labore et dolore magna aliqua']
How can I do the same, but only knowing the beginning of a word? For example, I’d like to split the string by “consect*” and having it split at the match of “consectetur”. Thanks
Use
\wto match any word character, or[A-Za-z]if you want only ASCII alpabetic characters.