Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Split Sentences Using Regex | Intermediate Regular Expressions
Python Regular Expressions

bookChallenge: Split Sentences Using Regex

Apply your regex knowledge to a practical text processing scenario. Your goal is to write a function that splits a paragraph into individual sentences. Each sentence ends with a period ('.'), exclamation mark ('!'), or question mark ('?'). Sentences may be followed by spaces or line breaks, and you should ensure that punctuation is included with each sentence in the output.

Key requirements:

  • Use the re module for regular expressions;
  • Detect sentence boundaries at '.', '!', or '?';
  • Include the punctuation mark at the end of each sentence;
  • Remove leading and trailing whitespace from each sentence.

Example input:

paragraph = "Hello there! How are you? I hope you're enjoying learning Python."

Expected output:

['Hello there!', 'How are you?', "I hope you're enjoying learning Python."]

Use this challenge to strengthen your understanding of regex splitting and sentence boundary detection in Python.

Tehtävä

Swipe to start coding

Write a function that splits a paragraph into sentences using regular expressions. Each sentence should end with a period, exclamation mark, or question mark. Sentences may be separated by spaces or line breaks, and you must include the punctuation mark at the end of each sentence in the output. Remove any leading or trailing whitespace from each sentence. Return a list of the sentences found in the paragraph.

Ratkaisu

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 5
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

close

Awesome!

Completion rate improved to 6.67

bookChallenge: Split Sentences Using Regex

Pyyhkäise näyttääksesi valikon

Apply your regex knowledge to a practical text processing scenario. Your goal is to write a function that splits a paragraph into individual sentences. Each sentence ends with a period ('.'), exclamation mark ('!'), or question mark ('?'). Sentences may be followed by spaces or line breaks, and you should ensure that punctuation is included with each sentence in the output.

Key requirements:

  • Use the re module for regular expressions;
  • Detect sentence boundaries at '.', '!', or '?';
  • Include the punctuation mark at the end of each sentence;
  • Remove leading and trailing whitespace from each sentence.

Example input:

paragraph = "Hello there! How are you? I hope you're enjoying learning Python."

Expected output:

['Hello there!', 'How are you?', "I hope you're enjoying learning Python."]

Use this challenge to strengthen your understanding of regex splitting and sentence boundary detection in Python.

Tehtävä

Swipe to start coding

Write a function that splits a paragraph into sentences using regular expressions. Each sentence should end with a period, exclamation mark, or question mark. Sentences may be separated by spaces or line breaks, and you must include the punctuation mark at the end of each sentence in the output. Remove any leading or trailing whitespace from each sentence. Return a list of the sentences found in the paragraph.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 5
single

single

some-alt