Celeb Glow
news | March 01, 2026

How to use REGEX to capitalise the first letter of each word in a sentence?

I would like to use regular expressions (REGEX) to capitalise the first letter of each word in a sentence.

I have achieved the same result in programming languages, but it seems that using regular expressions would be more concise.

4

1 Answer

Example using sed command.

~$ echo "foo bar" | sed 's/^\(.\)/\U\1/'

Where:

  • the ^ represents the start of a line.
  • . matches any character.
  • \U converts to uppercase.
  • \( ... \) specifies a section to be referenced later (as \1 in this case).
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy