Relative Content

Tag Archive for pythonpython-3.xregex

why is using regex group feature on Python giving different Outputs

import re string1 = “aaabaa” zusuchen = “aa” #1 m_start = re.finditer(fr'(?=({zusuchen}))’, string1) results = [(match.start(1), match.end(1)-1) for match in m_start] for z in results: print(z) print(“Now #2:”) #2 m_start = re.finditer(fr'(?={zusuchen})’, string1) results = [(match.start(), match.end()-1) for match in m_start] for z in results: print(z) I still haven’t figured out what’s the problem for […]

Why Is my Regex Is Unable to Find Sentences at the End of Text?

I am using python to parse emails to feed into an LLM and I need to truncate these emails if the text is too long. I am using TikToken to check length and I want to strip out text one sentence at a time – with a sentence starting with anything but always ending with a period, exclamation point, question mark or new line return (nr).