Regex to Match Title Case Words
Validate Title Case text where each word starts with an uppercase letter followed by lowercase letters. Matches properly capitalized titles. Free regex tester.
Regular Expression
/^(?:[A-Z][a-z]+(?:\s+|$))+$/
Token Breakdown
| Token | Description |
|---|---|
| ^ | Anchors at the start of the string (or line in multiline mode) |
| (?: | Start of non-capturing group |
| [A-Z] | Character class — matches any one of: A-Z |
| [a-z] | Character class — matches any one of: a-z |
| + | Matches the preceding element one or more times (greedy) |
| (?: | Start of non-capturing group |
| \s | Matches any whitespace character (space, tab, newline) |
| + | Matches the preceding element one or more times (greedy) |
| | | Alternation — matches the expression before OR after the pipe |
| $ | Anchors at the end of the string (or line in multiline mode) |
| ) | End of group |
| ) | End of group |
| + | Matches the preceding element one or more times (greedy) |
| $ | Anchors at the end of the string (or line in multiline mode) |
Detailed Explanation
This regex validates text written in Title Case, where every word begins with a capital letter followed by at least one lowercase letter. Here is the token-by-token breakdown:
^ — Anchors the match at the start of the string.
(?: — Opens a non-capturing group for each Title Case word.
[A-Z] — Matches a single uppercase letter at the start of each word. This is the defining characteristic of Title Case: every word must begin with a capital letter.
[a-z]+ — Matches one or more lowercase letters following the initial capital. This requires at least one lowercase letter per word, which distinguishes Title Case from ALL CAPS. Words like Hello and World match, but single uppercase letters or all-caps words do not.
(?:\s+|$) — Matches either one or more whitespace characters between words or the end of the string after the last word. This ensures words are space-separated and allows the pattern to match at the end of the input.
)+ — The word group repeats one or more times, requiring at least one word.
$ — Anchors the match at the end of the string.
No flags are used since case sensitivity is essential for Title Case validation.
Title Case is commonly used in headings, book titles, article titles, and proper nouns. For example: Hello World, The Great Gatsby, Data Structures And Algorithms. This pattern enforces strict Title Case where every word must start with a capital followed by lowercase letters.
Note that natural English title case has more complex rules where certain small words like a, the, in, and of are not capitalized unless they are the first word. This pattern enforces simplified strict Title Case. For natural English title case rules, more sophisticated logic beyond regex would be needed.
Example Test Strings
| Input | Expected |
|---|---|
| Hello World | Match |
| The Quick Brown Fox | Match |
| not title case | No Match |
| ALL CAPS | No Match |
| Single | Match |
Try It — Interactive Tester
27 charsFlags: noneMatches: 0Ctrl+Shift+C to copy regex