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

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

Re: Another regex problem


From: Pascal Bourguignon
Subject: Re: Another regex problem
Date: Tue, 25 Oct 2005 23:47:11 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

exits funnel <exitsfunnel@yahoo.com> writes:

> Hello,
>
> I've bumped into another problem which I'd like to use
> query-replace-regexp to fix if possible.  Not I've got
> a bunch of these:
>
> t_foo_Grape_Banana
> t_foo_Pear
> t_foo_Apple
>
> which I'd like to replace with
> t_foo_grape_banana
> t_foo_pear
> t_foo_apple
>
> In other words I'd like to make them uniformly lower
> case but I can't figure out how to accomplish this in
> the replacement string.  Is it possible?  Thanks in
> advance.

If you must downcase only part of the substitution, I don't know other
ways than to write some emacs lisp, or awk.  Something like:

(while (re-search-forward regexp nil t)
   (let ((p1 (match-string 1))
         (p2 (match-string 2))
         ...
         (pn (match-string n)))
    (delete-region (match-beginning) (match-end))
    (insert (format "...%s...%s...%s..." p1 (downcase p2) ... pn))))



Anyways, if you like to process flex/bison (or lex/yacc) files like
this, it may be a good idea not to make it a one-shoot affair, but to
keep the transformation in a script or a Makefile.  In general when I
use flex/bison, I've got a number of pre and post processing of the
sources in Makefile, with sed & awk.  For more sophisticated
transformations, emacs could be used (in batch mode ;-).

-- 
"A TRUE Klingon warrior does not comment his code!"


reply via email to

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