/**
 * Given a pattern and a piece of text, find the first sentence that matches the pattern and return it.
 *
 * @param pattern A regular expression pattern.
 * @param text A string containing multiple sentences.
 * @return The first sentence that matches the pattern, or null if no match is found.
 *
 * Example:
 * findSentence("[A-Z]\\w+".toRegex(), "This is a sample sentence. Another sentence is coming up.")
 * Output: "This is a sample sentence."
 */
fun findSentence(pattern: Regex, text: String): String? {

    val sentences = text.split(Regex("(?<!\\w\\.\\w.)(?<![A-Z][a-z]\\.)(?<=\\.|\\?)\\s"))
    for (sentence in sentences) {
        if (pattern.containsMatchIn(sentence)) {
            return sentence
        }
    }
    return null
}
/**
 * Given a pattern and a piece of text, find the first sentence that matches the pattern and return it.
 *
 * @param pattern A regular expression pattern.
 * @param text A string containing multiple sentences.
 * @return The first sentence that matches the pattern, or null if no match is found.
 *
 * Example:
 * findSentence("[A-Z]\\w+".toRegex(), "This is a sample sentence. Another sentence is coming up.")
 * Output: "This is a sample sentence."
 */
fun findSentence(pattern: Regex, text: String): String? {
/**
 * Given a pattern and a piece of text, find the first sentence that matches the pattern and return it.
 *
 * @param pattern A regular expression pattern.
 * @param text A string containing multiple sentences.
 * @return The first sentence that matches the pattern, or null if no match is found.
 *
 * Example:
 * findSentence("[A-Z]\\w+".toRegex(), "This is a sample sentence. Another sentence is coming up.")
 * Output: "This is a sample sentence."
 */
fun findSentence(pattern: Regex, text: String): String? {

    val sentences = text.split(Regex("(?<!\\w\\.\\w.)(?<![A-Z][a-z]\\.)(?<=\\.|\\?)\\s"))
    for (sentence in sentences) {
        if (pattern.containsMatchIn(sentence)) {
            return sentence
        }
    }
    return null
}