Text Processingflags: g

Sentence Boundary

Matches sentence boundaries (punctuation followed by whitespace and a capital letter).

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("[.!?]\\s+(?=[A-Z])", "g");
const input = "Hello world. How are you? I'm fine!";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

Pattern

regexengine-agnostic
[.!?]\s+(?=[A-Z])   (flags: g)

Raw source: [.!?]\s+(?=[A-Z])

How it works

`[.!?]` matches terminating punctuation. `\s+` matches whitespace. `(?=[A-Z])` is a lookahead for a capital letter (marks where the next sentence begins).

Examples

Input

Hello world. How are you? I'm fine!

Matches

  • .
  • ?

Common use cases

  • Sentence splitting
  • NLP preprocessing
  • Reading-level analysis

Related patterns

Related concepts