Regex to Match Sentences
Match complete sentences in text with this regex. Captures text from capital letter to ending punctuation. Free online regex tool.
Regular Expression
/[A-Z][^.!?]*[.!?]/g
Token Breakdown
| Token | Description |
|---|---|
| [A-Z] | Character class — matches any one of: A-Z |
| [^.!?] | Negated character class — matches any character NOT in .!? |
| * | Matches the preceding element zero or more times (greedy) |
| [.!?] | Character class — matches any one of: .!? |
Detailed Explanation
This regex matches sentences in English text, from a capital letter to ending punctuation. Here is the token-by-token breakdown:
[A-Z] — A character class matching a single uppercase letter. Most English sentences begin with a capital letter, so this serves as the sentence start anchor.
[^.!?]* — A negated character class matching zero or more characters that are not sentence-ending punctuation (period, exclamation mark, or question mark). The * quantifier allows for empty content between the capital letter and the ending punctuation. This consumes all characters in the sentence body.
[.!?] — A character class matching exactly one sentence-ending punctuation mark: a period, exclamation mark, or question mark.
The g flag enables global matching to find all sentences in the text. This pattern provides a simple heuristic for sentence detection. It works well for standard prose where sentences start with a capital letter and end with terminal punctuation.
However, it has limitations. It may incorrectly split on abbreviations containing periods (e.g., 'Dr. Smith' or 'U.S.A.'), and it will not match sentences that do not start with a capital letter. For robust sentence tokenization, natural language processing libraries are recommended. This regex is best suited for quick text analysis, preview generation, or simple content extraction tasks where perfect accuracy is not critical.
Example Test Strings
| Input | Expected |
|---|---|
| Hello world. | Match |
| Is this a question? | Match |
| no capital | No Match |
| Wow! | Match |
| First. Second. | Match |
Try It — Interactive Tester
Match Highlighting(5 matches)
Matches & Capture Groups
17 charsFlags: gMatches: 5Ctrl+Shift+C to copy regex