Regex to Match Capitalized Words
Match words starting with an uppercase capital letter using this regex. Finds proper nouns and sentence-starting words in text. Free regex tester.
Regular Expression
/\b[A-Z][a-z]+\b/g
Token Breakdown
| Token | Description |
|---|---|
| \b | Word boundary assertion |
| [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) |
| \b | Word boundary assertion |
Detailed Explanation
This regex matches words that begin with an uppercase letter followed by one or more lowercase letters. Here is the token-by-token breakdown:
\b — A word boundary anchor at the start. This ensures the match begins at the start of a word, not in the middle of one. Word boundaries occur between a word character and a non-word character.
[A-Z] — A character class matching a single uppercase letter from A to Z. This ensures the word starts with a capital letter.
[a-z]+ — A character class matching one or more lowercase letters. The + quantifier requires at least one lowercase letter after the initial capital, so single uppercase letters like 'I' or acronyms like 'NASA' will not match.
\b — A word boundary anchor at the end, ensuring the match ends at a word boundary.
The g flag enables global matching to find all capitalized words in the text. This pattern is useful for identifying proper nouns (names, places, organizations), sentence starters, and title-cased words in text. It matches words like 'Hello', 'Python', 'January', and 'London'.
Note that this pattern will not match all-caps words like 'NASA' or 'HTTP', mixed-case words like 'McDonald', or words with numbers like 'Python3'. For those cases, you would need modified patterns. This simple pattern works well for basic natural language processing tasks like named entity recognition preprocessing or text analysis.
Example Test Strings
| Input | Expected |
|---|---|
| Hello | Match |
| world | No Match |
| Python | Match |
| NASA | No Match |
| London | Match |
Try It — Interactive Tester
Match Highlighting(3 matches)
Matches & Capture Groups
15 charsFlags: gMatches: 3Ctrl+Shift+C to copy regex