Sentence Boundary in JS
Matches sentence boundaries (punctuation followed by whitespace and a capital letter).
Try it in the JS tester →Pattern
regexJS
[.!?]\s+(?=[A-Z]) (flags: g)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).
How the pattern 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
.?