[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: regex question
From: |
Barry Margolin |
Subject: |
Re: regex question |
Date: |
Mon, 19 May 2003 19:07:09 GMT |
In article <87znljuide.fsf@web.de>, upro <upro@gmx.net> wrote:
>This might be a stupid question:
>
>I want to use M-x replace-regexp like this
>
>s/[a-z]''/$1"/g
>
>the first part [a-z]'' works, but then the mathed lowercase letter is
>not reinserted, but a litteral $1.
If you want to grab a part of the matched text, you should use \<digit>,
etc.; $<digit> is Perl's equivalent, but most other regexp packages use
\<digit>.
Also, you need to put parentheses around the part that you want it to
remember. So it should be:
Old: \([a-z]\)''
New: \1"
>How does that work in emacs-regex? I don't find the relevant info in
>the info file...
File: emacs, Node: Regexp Replace
Regexp Replacement
------------------
The `M-x replace-string' command replaces exact matches for a single
string. The similar command `M-x replace-regexp' replaces any match
for a specified pattern.
In `replace-regexp', the NEWSTRING need not be constant: it can
refer to all or part of what is matched by the REGEXP. `\&' in
NEWSTRING stands for the entire match being replaced. `\D' in
NEWSTRING, where D is a digit, stands for whatever matched the Dth
parenthesized grouping in REGEXP. To include a `\' in the text to
replace with, you must enter `\\'. For example,
--
Barry Margolin, barry.margolin@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.