Thread: Regex examples
View Single Post
Old 11-18-2014, 03:01 PM   #437
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by Buchstabensalat View Post
Hi,

Thank you.

Using Sigil`s search (regex mode) your first string finds every single word in the text, the second string matches every uppercase word in my text and not only those that meet my search criteria ( uppercase letter(s) within a word). Is there a possiblity to match only those words with upercase letters in the word ?

Thanks again

Regards,

Buchstabensalat
I would use the following:

Find:
Code:
\b(\p{L})((?:\p{Ll}*\p{Lu})+\p{Ll}*)\b
Replace:
Code:
\1\L\2\E
NOTE: This uses unicode code points, on recommendation. Also, I have specifically saved the current case value of the first letter of the word, rather than assuming all words are lowercase.

Other than that, the only real difference from Doitsu's regex is that I specifically looked for uppercase letters inside the match, rather than applying an equalizer on all words -- this has the same result, but ignores matches where we wouldn't end up changing anything.
eschwartz is offline   Reply With Quote