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.
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.
Example using sed command.
~$ echo "foo bar" | sed 's/^\(.\)/\U\1/'
Where:
^ 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).\U - everything following in uppercase, \u next character only in uppercase
– Mark Jeronimus
Aug 15 '18 at 09:32
alias reg { var %x = 1, %y = $$1, %z while (%x <= $numtok(%y,32)) { %z = %z $+($upper($left($gettok(%y,%x,32),1)),$mid($gettok(%y,%x,32),$iif($len($gettok(%y,%x,32)) == 1,$remove(%x,$right($gettok(%y,%x,32),1)),$+(-,$calc($len($gettok(%y,%x,32)) - 1))))) inc %x } return %z }
– Sirius_Black May 03 '14 at 02:07