all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* regex question
@ 2003-05-19 14:21 upro
  2003-05-19 15:52 ` Danilo Segan
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: upro @ 2003-05-19 14:21 UTC (permalink / raw)


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.

How does that work in emacs-regex? I don't find the relevant info in
the info file...

Of course I could use \w'' - but I want to know how it works!

Thank You In Advance...

-- 
Michael

r-znvy: zvpunry.wryqra  jro.qr (chg gur "@" jurer vg svgf...)
ab fcnz cyrnfr

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: regex question
  2003-05-19 14:21 upro
@ 2003-05-19 15:52 ` Danilo Segan
  2003-05-19 17:20   ` upro
  2003-05-19 16:18 ` Jesper Harder
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Danilo Segan @ 2003-05-19 15:52 UTC (permalink / raw)


upro wrote:
> This might be a stupid question:
> 
> I want to use M-x replace-regexp like this
> 
> s/[a-z]''/$1"/g
> 
What are you, a Perl guy? :-)

Better try:
s/\([a-z]\)''/\1"/g

Cheers,
Danilo

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: regex question
  2003-05-19 14:21 upro
  2003-05-19 15:52 ` Danilo Segan
@ 2003-05-19 16:18 ` Jesper Harder
  2003-05-19 16:26 ` Kai Großjohann
  2003-05-19 19:07 ` Barry Margolin
  3 siblings, 0 replies; 11+ messages in thread
From: Jesper Harder @ 2003-05-19 16:18 UTC (permalink / raw)


upro <upro@gmx.net> writes:

> I want to use M-x replace-regexp like this
>
> s/[a-z]''/$1"/g

I'm not sure what this means, but I assume you want to replace stuff
like a'' with a".

> the first part [a-z]'' works, but then the mathed lowercase letter is
> not reinserted, but a litteral $1.
>
> How does that work in emacs-regex? I don't find the relevant info in
> the info file...

You could do:

   `M-x replace-regexp RET \([a-z]\)'' RET \1" RET'

Regexp syntax in Emacs is described in <info://emacs/Regexps>.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: regex question
  2003-05-19 14:21 upro
  2003-05-19 15:52 ` Danilo Segan
  2003-05-19 16:18 ` Jesper Harder
@ 2003-05-19 16:26 ` Kai Großjohann
  2003-05-19 19:07 ` Barry Margolin
  3 siblings, 0 replies; 11+ messages in thread
From: Kai Großjohann @ 2003-05-19 16:26 UTC (permalink / raw)


upro <upro@gmx.net> writes:

> I want to use M-x replace-regexp like this
>
> s/[a-z]''/$1"/g

In Emacs, you need to use \1 instead of $1, I think.  (You may have
to use \\1.)

Also, \1 always refers to a matching parenthesis, and square brackets
are not regarded as parens for this purpose.  So you need to say
\([a-z]\) if you use it interactively and \\([a-z]\\) if you use it
from Lisp.
-- 
This line is not blank.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: regex question
  2003-05-19 15:52 ` Danilo Segan
@ 2003-05-19 17:20   ` upro
  0 siblings, 0 replies; 11+ messages in thread
From: upro @ 2003-05-19 17:20 UTC (permalink / raw)


Danilo Segan <danilo@kvota.net> writes:

> upro wrote:
>> This might be a stupid question:
>> I want to use M-x replace-regexp like this
>> s/[a-z]''/$1"/g
>>
> What are you, a Perl guy? :-)
>
> Better try:
> s/\([a-z]\)''/\1"/g

Got me - I'm a Perl guy...

I apparently forgot to backslash the parentheses....

Thanks a lot, Michael

>
> Cheers,
> Danilo
>

-- 
Michael

r-znvy: zvpunry.wryqra  jro.qr (chg gur "@" jurer vg svgf...)
ab fcnz cyrnfr

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: regex question
  2003-05-19 14:21 upro
                   ` (2 preceding siblings ...)
  2003-05-19 16:26 ` Kai Großjohann
@ 2003-05-19 19:07 ` Barry Margolin
  3 siblings, 0 replies; 11+ messages in thread
From: Barry Margolin @ 2003-05-19 19:07 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* regex question
@ 2007-09-02 17:11 Dave Pawson
  2007-09-02 18:31 ` Peter Dyballa
  0 siblings, 1 reply; 11+ messages in thread
From: Dave Pawson @ 2007-09-02 17:11 UTC (permalink / raw)
  To: emac

I have text reading 'try>Letter'  e.g. 'try[A'
and I want to do a search/replace using regex.

I want to replace it with 'try text>A

I.e. I want to retain the group ([A-E])
so that the finished text reads 'try text>A

Does emacs regex support groups please?

TIA

-- 
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: regex question
       [not found] <mailman.176.1188753116.18990.help-gnu-emacs@gnu.org>
@ 2007-09-02 18:30 ` Tassilo Horn
  2007-09-03  6:52   ` Dave Pawson
  2007-09-02 18:44 ` Harald Hanche-Olsen
  1 sibling, 1 reply; 11+ messages in thread
From: Tassilo Horn @ 2007-09-02 18:30 UTC (permalink / raw)
  To: help-gnu-emacs

"Dave Pawson" <dave.pawson@gmail.com> writes:

> I have text reading 'try>Letter'  e.g. 'try[A'
> and I want to do a search/replace using regex.
>
> I want to replace it with 'try text>A
>
> I.e. I want to retain the group ([A-E])
> so that the finished text reads 'try text>A
>
> Does emacs regex support groups please?

Sure it does.

M-x replace-regexp \(try\)\(\>.\) RET \1 text\2 RET

Bye,
Tassilo
-- 
Früher haben wir vor dem Essen  immer gebetet, aber jetzt hat meine Frau
einen Kochkurs gemacht.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: regex question
  2007-09-02 17:11 regex question Dave Pawson
@ 2007-09-02 18:31 ` Peter Dyballa
  0 siblings, 0 replies; 11+ messages in thread
From: Peter Dyballa @ 2007-09-02 18:31 UTC (permalink / raw)
  To: Dave Pawson; +Cc: emac


Am 02.09.2007 um 19:11 schrieb Dave Pawson:

> Does emacs regex support groups please?

Yes: \(first group\)some\(second group\)thing\(third group\) -> some 
\3other\2thing\1too

--
Greetings

   Pete

"A lot of people mistake a short memory for a clear conscience."
                                                      Doug Larson

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: regex question
       [not found] <mailman.176.1188753116.18990.help-gnu-emacs@gnu.org>
  2007-09-02 18:30 ` Tassilo Horn
@ 2007-09-02 18:44 ` Harald Hanche-Olsen
  1 sibling, 0 replies; 11+ messages in thread
From: Harald Hanche-Olsen @ 2007-09-02 18:44 UTC (permalink / raw)
  To: help-gnu-emacs

+ "Dave Pawson" <dave.pawson@gmail.com>:

> I have text reading 'try>Letter'  e.g. 'try[A'
> and I want to do a search/replace using regex.

I'm confused.  Is that '[' above a typo, or do you have some problem
that is more complicated than it looks?

> I want to replace it with 'try text>A
>
> I.e. I want to retain the group ([A-E])
> so that the finished text reads 'try text>A
>
> Does emacs regex support groups please?

Yes.  I assume you have checked the info file that comes with emacs?
There is a whole section devoted to regular expressions.  The answer
you seek seems to be in a separate section (Regexp Backslash), at
least in the version I am currently using.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: regex question
  2007-09-02 18:30 ` Tassilo Horn
@ 2007-09-03  6:52   ` Dave Pawson
  0 siblings, 0 replies; 11+ messages in thread
From: Dave Pawson @ 2007-09-03  6:52 UTC (permalink / raw)
  To: Tassilo Horn, emac

On 02/09/07, Tassilo Horn <tassilo@member.fsf.org> wrote:

> > I.e. I want to retain the group ([A-E])
> > so that the finished text reads 'try text>A
> >
> > Does emacs regex support groups please?
>
> Sure it does.
>
> M-x replace-regexp \(try\)\(\>.\) RET \1 text\2 RET

\1 to insert the text!
Yet another case where emacs can do it, just need to find out how!

Many thanks Tassilo.
No Harald, I'd tried the book and failed.
I'll try the info file now.

Thanks to you and Peter for the response.

regard



-- 
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-09-03  6:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-02 17:11 regex question Dave Pawson
2007-09-02 18:31 ` Peter Dyballa
     [not found] <mailman.176.1188753116.18990.help-gnu-emacs@gnu.org>
2007-09-02 18:30 ` Tassilo Horn
2007-09-03  6:52   ` Dave Pawson
2007-09-02 18:44 ` Harald Hanche-Olsen
  -- strict thread matches above, loose matches on Subject: below --
2003-05-19 14:21 upro
2003-05-19 15:52 ` Danilo Segan
2003-05-19 17:20   ` upro
2003-05-19 16:18 ` Jesper Harder
2003-05-19 16:26 ` Kai Großjohann
2003-05-19 19:07 ` Barry Margolin

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.