help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: capitalize string using regular expressions


From: Tim Heaney
Subject: Re: capitalize string using regular expressions
Date: Fri, 05 Dec 2003 21:19:04 -0500
User-agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Rational FORTRAN, linux)

"colin smith" <zxcv4856@hotmail.com> writes:
>
>     Does anyone know how I can replace all occurences of  any strings that
> end with ".txt" (lets say "ghjkl.txt" and "xyz.txt") with their uppercase
> equivalents(ie. "GHJKL.txt" and "XYZ.txt").  There must be some way of doing
> this using regular expressions. I've looked extensively through the emacs
> help, but havent been able to figure it out.

Hm. I couldn't quite figure it out either. Here's how you might do it
in Perl

  perl -i~ -pe 's/\b(\w+)(\.txt)\b/uc($1).$2/ge' file

That is, if that's run from the command line then file will be edited
and file~ will be the original. In emacs, I don't know how to
uppercase part of the search string like that. I guess you could
define a macro to do it:

  C-x (              ; start recording macro
  C-M-s              ; start regular expression search 
  \<[a-z]+\.txt\>    ; regular expression to search for
  M-4 C-b            ; move back 4 places (the .txt)
  M-- M-u            ; uppercase previous word
  C-x )              ; stop recording macro

Then to execute the macro, keep hitting 

  C-x e 

as many times as you need. I dunno. Perhaps someone else will post a
more straightforward way to do it.

Tim


reply via email to

[Prev in Thread] Current Thread [Next in Thread]