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])/g
Open it in Rex

The problem

Turn camelCase or PascalCase identifiers into kebab-case or a readable label.

How it reads

1[a-z0-9]2[A-Z]

Follow the line from left to right — every path you can trace is a string this pattern matches.

  1. ([a-z0-9])([A-Z])In order:
  2. ([a-z0-9])Capture group 1:
  3. [a-z0-9]Any one of: "a" to "z" or "0" to "9"
  4. ([A-Z])Capture group 2:
  5. [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.

More text & extraction patterns