Quote:
Originally Posted by wydchr
getting back to 'The A.B.C. Murders', is there a way of capturing a string like A.b.c. and capitalising that.
|
The regular expression "((?<= |\.|-)|^)([a-z]+)(?= |\.|-|$)" will capitalize any "word" separated by spaces, periods, or hyphens (actually dashes), in any combination. For example, using that regexp the string
iTunes is not built by IBM or by Alcatel-lucent but by apple with a.b.c
results in
iTunes Is Not Built By IBM Or By Alcatel-Lucent But By Apple With A.B.C
The change to the regexp is to enlarge the set of characters that must precede and follow a word to permit it to be a candidate for capitalization.
And you are welcome.
Edit: the following regexp is better, changing the alternation ("or") to a character class. I think it is easier to read. "((?<=[ \.-])|^)([a-z]+)(?=[ \.-]|$)"