Sentence Splitting with Regex

Using regular expressions to split text into sentences, handling various edge cases

import re

def split_sentences(text):
    pattern = r'(?<!\w\.\w.)(?<![A-Z][a-z]\.)(?<=\.|\?|\!)\s'
    return re.split(pattern, text)

sample_text = "Hello, world! This is a test. Mr. Smith went to Washington D.C. Is this working?"
sentences = split_sentences(sample_text)
for i, sentence in enumerate(sentences, 1):
    print(f"{i}. {sentence}")