I'm trying to improve upon my Vim skills and was randomly googling for "vim regex challenge" when I came upon this thread, and decided to pick up the challenge.
I think I've come up with something that finds an uppercase alphabetical character that is not immediately preceded by the beginning of the file, the beginning of a line or a ., ! or ? followed by a space or tab and substitutes it with itself in lowercase.
If you accept every prompt, the following text:
The vi editor has a command, tilde (~),
that changes lowercase letters to
uppercase and vice versa.
Unfortunately the ~ command does not
work with a Unit of Measure or
a Repeat Factor, so you have to change
the case one character at a time.
Hello. I am Joe.
HOLA! I am José! Why are you looking at me weird? Is something WRONG?
becomes:
The vi editor has a command, tilde (~),
that changes lowercase letters to
uppercase and vice versa.
Unfortunately the ~ command does not
work with a unit of measure or
a repeat factor, so you have to change
the case one character at a time.
Hello. I am joe.
Hola! I am josé! Why are you looking at me weird? Is something wrong?
And it goes:
%s/\%^\@<!\_^\@<!\([.!?]\s\)\@<!\(\u\)/\l\2/gc
I'm sure it's very verbose - it could probably be shorter with magic or very magic. Possibly, the three negative lookbehinds could be reduced to one somehow, or substituted with something more elegant.
This is my first post on this ancient-by-internet-standards thread on a forum I've never seen before, but I just couldn't leave it hanging after constructing my own attempt