unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Help with query-replace-regular expression
@ 2006-09-11 13:22 jade_lindquist
  2006-09-11 13:45 ` David Kastrup
  2006-09-11 14:01 ` Jim Ottaway
  0 siblings, 2 replies; 5+ messages in thread
From: jade_lindquist @ 2006-09-11 13:22 UTC (permalink / raw)


I'm struggling with emacs' implementation of regexp. I'd certainly
appreciate some pointers.

I'd like to replace lines like: /*#midp1_0#*///<editor-fold>

with:

//#if midp1_0

the phrase midp1_0 could be debug or some other alpha plus _ sequence

Thus I've tried M-x query-tags-regexp:
from:  \\/\\*\\#\\([a-zA-Z_]+\\).*
to: //#if \\1

but I don't get any matches.

Pehaps I need to escape other characters?

Thanks,
jdl

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

* Re: Help with query-replace-regular expression
  2006-09-11 13:22 Help with query-replace-regular expression jade_lindquist
@ 2006-09-11 13:45 ` David Kastrup
  2006-09-11 14:01 ` Jim Ottaway
  1 sibling, 0 replies; 5+ messages in thread
From: David Kastrup @ 2006-09-11 13:45 UTC (permalink / raw)


jade_lindquist@hotmail.com writes:

> I'm struggling with emacs' implementation of regexp. I'd certainly
> appreciate some pointers.
>
> I'd like to replace lines like: /*#midp1_0#*///<editor-fold>
>
> with:
>
> //#if midp1_0
>
> the phrase midp1_0 could be debug or some other alpha plus _ sequence
>
> Thus I've tried M-x query-tags-regexp:
> from:  \\/\\*\\#\\([a-zA-Z_]+\\).*
> to: //#if \\1

Good grief.  You are using string syntax and escape far too much.
Just replace
/\*#\([a-zA-Z]+\).*
with
//#if \1

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

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

* Re: Help with query-replace-regular expression
  2006-09-11 13:22 Help with query-replace-regular expression jade_lindquist
  2006-09-11 13:45 ` David Kastrup
@ 2006-09-11 14:01 ` Jim Ottaway
  2006-09-11 15:37   ` Eric Hanchrow
  1 sibling, 1 reply; 5+ messages in thread
From: Jim Ottaway @ 2006-09-11 14:01 UTC (permalink / raw)


jade_lindquist@hotmail.com writes:

> I'm struggling with emacs' implementation of regexp. I'd certainly
> appreciate some pointers.
>
> I'd like to replace lines like: /*#midp1_0#*///<editor-fold>
>
> with:
>
> //#if midp1_0
>
> the phrase midp1_0 could be debug or some other alpha plus _ sequence
>
> Thus I've tried M-x query-tags-regexp:
> from:  \\/\\*\\#\\([a-zA-Z_]+\\).*
> to: //#if \\1
>
> but I don't get any matches.
>
> Pehaps I need to escape other characters?

You need fewer escapes, and to add 0-9 to the character alternatives:

M-x query-replace-regexp 
from: /\*#\([a-zA-Z0-9_]+\)#\*///<editor-fold>  
to: //#if \1

or you can use a character class:
from: /\*#\([[:alnum:]_]+\)#\*///<editor-fold>

Regards,

-- 
Jim Ottaway

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

* Re: Help with query-replace-regular expression
  2006-09-11 14:01 ` Jim Ottaway
@ 2006-09-11 15:37   ` Eric Hanchrow
  2006-09-11 15:57     ` Jim Ottaway
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Hanchrow @ 2006-09-11 15:37 UTC (permalink / raw)


Or escape "escape hell" and let "rx" write the regexp for you:

(rx "/*#" (group (or (any alpha) "_")
                 (or (any alnum) "_")) "#*/")
That evaluates to

"\\(?:/\\*#\\(\\(?:\\(?:[[:alpha:]]\\)\\|_\\)\\(?:\\(?:[[:alnum:]]\\)\\|_\\)\\)#\\*/\\)"
-- 
The only form of intelligence that really matters is the capacity to predict.
        -- Colin Blakemore

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

* Re: Help with query-replace-regular expression
  2006-09-11 15:37   ` Eric Hanchrow
@ 2006-09-11 15:57     ` Jim Ottaway
  0 siblings, 0 replies; 5+ messages in thread
From: Jim Ottaway @ 2006-09-11 15:57 UTC (permalink / raw)


Eric Hanchrow <offby1@blarg.net> writes:

> Or escape "escape hell" and let "rx" write the regexp for you:
>
> (rx "/*#" (group (or (any alpha) "_")
>                  (or (any alnum) "_")) "#*/")
> That evaluates to
>
> "\\(?:/\\*#\\(\\(?:\\(?:[[:alpha:]]\\)\\|_\\)\\(?:\\(?:[[:alnum:]]\\)\\|_\\)\\)#\\*/\\)"

I don’t think you need both alpha and alnum, do you?.  Anyhow, nice
though rx is, you don’t get something that can be used for interactive
use of query-replace-regexp, since the escaping is for a string, rather
than for text entered in the minibuffer, where you don’t have to
double-escape the backslashes.

Regards,

-- 
Jim Ottaway

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

end of thread, other threads:[~2006-09-11 15:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-11 13:22 Help with query-replace-regular expression jade_lindquist
2006-09-11 13:45 ` David Kastrup
2006-09-11 14:01 ` Jim Ottaway
2006-09-11 15:37   ` Eric Hanchrow
2006-09-11 15:57     ` Jim Ottaway

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).