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.
41 Answer
Example using sed command.
~$ echo "foo bar" | sed 's/^\(.\)/\U\1/'Where:
- the
^represents the start of a line. .matches any character.\Uconverts to uppercase.\( ... \)specifies a section to be referenced later (as\1in this case).