How to search / replace capital letter in middle of word

Find, replace, find in files, replace in files, regular expressions

How to search / replace capital letter in middle of word

Postby Nick » Wed Feb 09, 2011 12:28 pm

Hi

How I can search and replace capital letter which is:

1. not on beginning of the sentence and in middle or end of some word - They are walKing. - here I need to find capital K and replace it with k

2. not on beginning of sentence but on beginning of one word in sentence - They are Walking. - here I need to find capital W and replace it with w

I tried find with ^[^K].*[K] but it is not good one.

Thanks
User avatar
Nick
Newbie
 
Posts: 8
Joined: Wed Jan 17, 2007 12:00 am

Re: How to search / replace capital letter in middle of word

Postby pietzcker » Wed Feb 09, 2011 1:04 pm

Activate Perl regular expression and make sure that the case sensitivity option is turned on. Then search for
Code: Select all
(?<!^)(?<![.!:?] )([A-Z])

and replace with
Code: Select all
\L\1


The first regex checks that the current character is neither at the start of a line nor directly following a punctuation character and a space. Then it tries to match an uppercase letter. The replace operation converts that into lowercase.

It's not a very reliable solution, but then how reliably can you tell whether you're at the start or in the middle of a sentence?
User avatar
pietzcker
Master
Master
 
Posts: 242
Joined: Sun Aug 22, 2004 11:00 pm

Re: How to search / replace capital letter in middle of word

Postby Nick » Fri Feb 11, 2011 6:32 am

Thank You very much it works correctly
User avatar
Nick
Newbie
 
Posts: 8
Joined: Wed Jan 17, 2007 12:00 am


Return to Find/Replace/Regular Expressions

cron