Regex to Match camelCase Strings

Validate camelCase identifiers starting with a lowercase letter followed by alphanumeric characters with uppercase word boundaries. Free online regex tester.

Regular Expression

/^[a-z][a-zA-Z0-9]*$/

Token Breakdown

TokenDescription
^Anchors at the start of the string (or line in multiline mode)
[a-z]Character class — matches any one of: a-z
[a-zA-Z0-9]Character class — matches any one of: a-zA-Z0-9
*Matches the preceding element zero or more times (greedy)
$Anchors at the end of the string (or line in multiline mode)

Detailed Explanation

This regex validates strings written in camelCase notation, a naming convention widely used in JavaScript, Java, and other programming languages. Here is the token-by-token breakdown:

^ — Anchors the match at the start of the string, ensuring validation begins from the first character.

[a-z] — Matches a single lowercase letter as the first character. CamelCase requires the string to begin with a lowercase letter, distinguishing it from PascalCase which starts with an uppercase letter.

[a-zA-Z0-9]* — Matches zero or more alphanumeric characters for the remainder of the string. This allows lowercase letters, uppercase letters (which indicate word boundaries in camelCase), and digits. The absence of special characters like underscores, hyphens, or spaces is what defines camelCase.

$ — Anchors the match at the end of the string, ensuring no trailing characters exist.

No flags are used because case sensitivity is essential for validating camelCase, as the distinction between lowercase and uppercase letters defines the word boundaries.

CamelCase is the standard naming convention for variables and functions in JavaScript, for example: firstName, getUserData, calculateTotalPrice, and xmlHttpRequest. It is also used in Java for method and variable names.

This pattern validates the structural form of camelCase but does not enforce that uppercase letters actually appear within the string. A string like hello would also match since it is a valid single-word camelCase identifier. For strict enforcement of at least one word boundary, the pattern would need to require at least one uppercase letter in the middle.

Example Test Strings

InputExpected
camelCaseMatch
firstNameMatch
PascalCaseNo Match
snake_caseNo Match
getElementByIdMatch
123invalidNo Match

Try It — Interactive Tester

//
gimsuy
No matches found.
Pattern: 19 charsFlags: noneMatches: 0

Ctrl+Shift+C to copy regex

Customize this pattern →