RegexBuilder · regex answers
Regex to capitalise the first letter
/^(\w)/
Capture the first word character so a replacement can upper-case it. Combined with the m and g flags it does the same to every line. Note the caveat: for scripts where a character upper-cases into two, only the language's own case functions are correct.
What each part does
| ^ | start of the string |
| (\w) | capture that first word character |
Tested against real input
Every row below was run through the engine when this page was built. The third column is the substring the pattern actually matched.
| Input | Result | Matched |
|---|---|---|
| hello | matches | h |
| hello world | matches | h |
| 1abc | matches | 1 |
| hello | no match | — |
| (empty string) | no match | — |
The mistake to avoid
Assuming it works for every alphabet. The German ß upper-cases to SS — two characters — and no single-character replacement handles that.
Try it on your own text
Paste this pattern and your input, see each match highlighted with its capture groups, step through what the engine did, and get the equivalent syntax for JavaScript, Python, Java, Go and PCRE.
Open RegexBuilderOther regex answers
- Regex for an email address
- Regex for a US phone number
- Regex for an IPv4 address
- Regex for a URL
- Regex for a date in YYYY-MM-DD format
- Regex to match digits only
- Regex for alphanumeric characters
- Regex to find special characters
- Regex for a strong password
- Regex to match whitespace
- Regex to trim leading and trailing whitespace
- Regex for a UUID