Skip to content

Instantly share code, notes, and snippets.

@dardanxhymshiti
Last active July 3, 2020 14:32
Show Gist options
  • Save dardanxhymshiti/9f1504a5d64627cbee9fcae8ec18626c to your computer and use it in GitHub Desktop.
Save dardanxhymshiti/9f1504a5d64627cbee9fcae8ec18626c to your computer and use it in GitHub Desktop.
def get_sentences(text):
import re
pattern = r'([A-Z][^\.!?]*[\.!?])'
pattern_compiled = re.compile(pattern, re.M)
list_of_sentences = re.findall(pattern, text)
return list_of_sentences
# Test
text = """This is the most frequent question we're asked by prospective students. And our response? Absolutely! We've trained people from all walks of life."""
get_sentences(text)
# [
# "This is the most frequent questions we're asked by prospective students.",
# 'And our response?',
# 'Absolutely!',
# "We've trained people from all walks of life."
# ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment