From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Tim Heaney Newsgroups: gmane.emacs.help Subject: Re: capitalize string using regular expressions Date: Fri, 05 Dec 2003 21:19:04 -0500 Organization: Posted via Supernews, http://www.supernews.com Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <87oeumzo13.fsf@mrbun.watterson> References: <3M9Ab.324$vg4.207@nwrdny02.gnilink.net> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1070677908 4143 80.91.224.253 (6 Dec 2003 02:31:48 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 6 Dec 2003 02:31:48 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Dec 06 03:31:46 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1ASSEU-0006BQ-00 for ; Sat, 06 Dec 2003 03:31:46 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AST9X-0008RO-PN for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Dec 2003 22:30:43 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-04!sn-xit-06!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail Original-Newsgroups: gnu.emacs.help X-Attribution: Tim X-URL: X-Face: 1d:<$[diLo"J3; Pu?&s98HAEv|@!_`rn#ymrsx]YVUA^?MOofFnmkmI{r!Z_V=6AmO_Yf7H LAv@J@y4f-!P-{ List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:14995 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:14995 "colin smith" 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