- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Regex in Practice
JavaScript Regular Expressions
JavaScript Regex in Practice
A few everyday patterns cover most of what regular expressions are used for.
In real work the same handful of patterns come up again and again.
It is also worth knowing when not to reach for one.
Example
Example
javascript
const messy = " too many spaces ";
console.log(messy.trim().replace(/\s+/g, " "));The output has single spaces throughout.
