• + 0 comments

    import re

    def split_sentences(text): # Define the regular expression pattern to match sentence boundaries pattern = r"""(?<=\w.)\s+"""

    # Split the text into sentences using the pattern
    sentences = re.split(pattern, text)
    
    # Clean up the sentences by removing leading and trailing whitespace and empty strings
    sentences = [sentence.strip() for sentence in sentences if sentence.strip()]
    
    # Handle sentences ending with common abbreviations (e.g., Dr., Mr., Mrs.)
    sentences = [sentence[:-1] if sentence.endswith(".") and sentence[-2:] in [".D", ".M", ".M"] else sentence for sentence in sentences]
    
    return sentences
    

    Get the input text from the user

    input_text = input("Enter your text: ")

    Split the text into sentences

    sentences = split_sentences(input_text)

    Print the sentences

    for sentence in sentences: print(sentence)