Regex patterns/Text & extraction
camelCase boundary
Two captures around the seam, so a replacement can insert a hyphen between them.
/([a-z0-9])([A-Z])/gThe problem
Turn camelCase or PascalCase identifiers into kebab-case or a readable label.
How it reads
Follow the line from left to right — every path you can trace is a string this pattern matches.
([a-z0-9])([A-Z])In order:([a-z0-9])Capture group 1:[a-z0-9]Any one of: "a" to "z" or "0" to "9"([A-Z])Capture group 2:[A-Z]Any one of: "A" to "Z"
Matches
- backgroundColor
- parseHTMLString
Does not match
- alreadykebab
- ALLCAPS
- snake_case
Where it bites
- Both characters must be captured because the match consumes them — replace with "$1-$2" and you keep them; replace with "-" and you lose them.
- Acronyms split awkwardly: parseHTMLString becomes parse-h-t-m-l-string. Handling those needs a second pass with a lookahead.
- A lookahead version ((?<=[a-z0-9])(?=[A-Z])) matches the empty seam instead, so the replacement needs no captures at all.