[Techtalk] RegEx problem in vim

Almut Behrens almut-behrens at gmx.net
Mon Jul 26 22:35:11 EST 2004


On Mon, Jul 26, 2004 at 03:06:50PM -0400, Tricia Bowen wrote:
> You might want to try this pattern to replace the space or newline at
> the same time:
> 
> :%s/\([A-Z]\)\([ \n]\)/\1.\2/g


I'd suggest to use the word boundary markers \< \>

:%s/\<\([A-Z]\)\>/\1./g

This nicely solves a couple of issues in one go.

(Hint: assume you had a title like "... in the US and ...".
Not using boundary markers would turn US into "US.", probably not what
you want...  Even if not strictly required for some given input, it's
generally a good idea to craft regexes as robust as possible against
unexpected input.)

Cheers,
Almut



More information about the Techtalk mailing list