View Single Post
Old 06-08-2012, 04:17 AM   #29
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by wydchr View Post
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]+)(?=[ \.-]|$)"

Last edited by chaley; 06-08-2012 at 04:20 AM. Reason: Add another variant
chaley is offline   Reply With Quote