unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Tim Heaney <theaney@cablespeed.com>
Subject: Re: capitalize string using regular expressions
Date: Fri, 05 Dec 2003 21:19:04 -0500	[thread overview]
Message-ID: <87oeumzo13.fsf@mrbun.watterson> (raw)
In-Reply-To: 3M9Ab.324$vg4.207@nwrdny02.gnilink.net

"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	other threads:[~2003-12-06  2:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-06  0:53 capitalize string using regular expressions colin smith
2003-12-06  2:19 ` Tim Heaney [this message]
2003-12-06  3:29 ` Greg Hill
2003-12-06  4:29 ` Pascal Bourguignon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oeumzo13.fsf@mrbun.watterson \
    --to=theaney@cablespeed.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).