Code
Match a camelCase identifier
Match variable names in camelCase like userName or fooBar42.
Pattern
Regular expression
\b[a-z]+(?:[A-Z][a-z0-9]*)+\bHow it works
Starts with lowercase word, then one or more segments starting with an uppercase followed by lowercase/digits. Requires at least one internal capital.
Matches
- ▸userName
- ▸fooBar42
- ▸getUserById
Non-matches
- ▸User (starts uppercase)
- ▸lower (no internal capital)
- ▸snake_case
Language snippets
JavaScript
const re = /\b[a-z]+(?:[A-Z][a-z0-9]*)+\b/g;Python
re.findall(r"\b[a-z]+(?:[A-Z][a-z0-9]*)+\b", text)Go
re := regexp.MustCompile(`\b[a-z]+(?:[A-Z][a-z0-9]*)+\b`)Java
Pattern.compile("\\b[a-z]+(?:[A-Z][a-z0-9]*)+\\b")Frequently asked questions
What is the regex for camelCase identifier?
The pattern \b[a-z]+(?:[A-Z][a-z0-9]*)+\b matches camelCase identifier. Starts with lowercase word, then one or more segments starting with an uppercase followed by lowercase/digits. Requires at least one internal capital.
What does this camelCase identifier pattern match?
It matches strings like userName, fooBar42, getUserById, but rejects User (starts uppercase), lower (no internal capital).
How do I use this pattern in JavaScript, Python, Go, Java?
Ready-to-run snippets are provided for JavaScript, Python, Go, Java. Copy the one for your language from the Language snippets section — each wraps the same core pattern in that language's regex API.