unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Converting a non-escaped regexp to an escaped version
@ 2007-06-07 12:32 HippoMan
  2007-06-07 14:14 ` Nikolaj Schumacher
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: HippoMan @ 2007-06-07 12:32 UTC (permalink / raw)
  To: help-gnu-emacs

During development of elisp code that I'm writing, I test regular
expressions via the interactive use of M-x re-search-forward.  Once
I've come up with a regexp that works, I often will want
to yank it into my elisp code, for example, into a call to
`match-string'.

Of course, once I do this, I then have to go through the regexp and
double all of the backslashes within it.  In order to make this easier
for myself, I'd like to have an elisp function that will yank a
string while auto-doubling every backslash it contains.  I'm happy to
write such a function, but before I re-invent the wheel, I'm
wondering if such a thing has already been invented.

In case this isn't clear, here's what I want to do:

1. Test a regular expression interactively, for example, via
   the use of M-x re-search-forward.

2. Assume that I finally decide that the following regexp is
   the one that I want to use within my elisp code:

     \bfoo\b.*:.*\bbar\([0-9]\{9\}quack\.quack\)\b

3. Put this regexp to the kill ring.

4. Use my proposed function to yank it into my elisp code
   (for example, within an invocation of `match-string'), as follows:

     \\bfoo\\b.*:.*\\bbar\\([0-9]\\{9\\}quack\\.quack\\)\\b

Note that I'm not asking any of you to write this function for
me, as I can do this.  I just want to know whether something
like this already exists within the emacs code base or perhaps
somewhere else on the net.

Thanks in advance.

--
 hippoman@gmail.com

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

* Re: Converting a non-escaped regexp to an escaped version
  2007-06-07 12:32 Converting a non-escaped regexp to an escaped version HippoMan
@ 2007-06-07 14:14 ` Nikolaj Schumacher
  2007-06-07 14:21 ` Juanma Barranquero
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Nikolaj Schumacher @ 2007-06-07 14:14 UTC (permalink / raw)
  To: HippoMan; +Cc: help-gnu-emacs

On 2007-06-07, at 14:32, HippoMan wrote:

> During development of elisp code that I'm writing, I test regular
> expressions via the interactive use of M-x re-search-forward.  Once
> I've come up with a regexp that works, I often will want
> to yank it into my elisp code, for example, into a call to
> `match-string'.

Not really a solution for your specific problem, but I'd suggest  
using `re-builder' for that.

regards,
Nikolaj Schumacher

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

* Re: Converting a non-escaped regexp to an escaped version
  2007-06-07 12:32 Converting a non-escaped regexp to an escaped version HippoMan
  2007-06-07 14:14 ` Nikolaj Schumacher
@ 2007-06-07 14:21 ` Juanma Barranquero
       [not found] ` <mailman.1734.1181225695.32220.help-gnu-emacs@gnu.org>
  2007-06-11  9:31 ` Johan Bockgård
  3 siblings, 0 replies; 8+ messages in thread
From: Juanma Barranquero @ 2007-06-07 14:21 UTC (permalink / raw)
  To: HippoMan; +Cc: help-gnu-emacs

On 6/7/07, HippoMan <hippoman@gmail.com> wrote:

> 1. Test a regular expression interactively, for example, via
>    the use of M-x re-search-forward.
>
> 2. Assume that I finally decide that the following regexp is
>    the one that I want to use within my elisp code:
>
>      \bfoo\b.*:.*\bbar\([0-9]\{9\}quack\.quack\)\b
>
> 3. Put this regexp to the kill ring.
>
> 4. Use my proposed function to yank it into my elisp code
>    (for example, within an invocation of `match-string'), as follows:
>
>      \\bfoo\\b.*:.*\\bbar\\([0-9]\\{9\\}quack\\.quack\\)\\b

You could use M-x re-builder to test your regexp, which is very nice,
supports several regexp syntaxes and can highlight subexpressions
(groups).

Then, inside the re-builder buffer, do C-c C-w (that's `reb-copy') to
copy the regexp.

             Juanma

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

* Re: Converting a non-escaped regexp to an escaped version
       [not found] ` <mailman.1734.1181225695.32220.help-gnu-emacs@gnu.org>
@ 2007-06-07 14:35   ` Joost Kremers
  2007-06-07 15:12     ` HippoMan
  0 siblings, 1 reply; 8+ messages in thread
From: Joost Kremers @ 2007-06-07 14:35 UTC (permalink / raw)
  To: help-gnu-emacs

Nikolaj Schumacher wrote:
> On 2007-06-07, at 14:32, HippoMan wrote:
>
>> During development of elisp code that I'm writing, I test regular
>> expressions via the interactive use of M-x re-search-forward.  Once
>> I've come up with a regexp that works, I often will want
>> to yank it into my elisp code, for example, into a call to
>> `match-string'.
>
> Not really a solution for your specific problem, but I'd suggest  
> using `re-builder' for that.

it can be a solution, though: re-builder supports different forms of input
syntax. by default, it requires you to escape backslashes, so that when you
type C-c C-w to copy the regexp to the kill-ring, you get it with every
backslash escaped.

if you don't want to type the double backslashes, you can change
re-builders input syntax (with C-c TAB)from "read" to "string". then,
before typing C-c C-w change it back again to "read": re-builder will
automatically adjust the syntax and escape all backslashes for you.

it's a pretty neat package, that re-builder.

-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)

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

* Re: Converting a non-escaped regexp to an escaped version
  2007-06-07 14:35   ` Joost Kremers
@ 2007-06-07 15:12     ` HippoMan
  2007-06-07 15:19       ` Joost Kremers
  0 siblings, 1 reply; 8+ messages in thread
From: HippoMan @ 2007-06-07 15:12 UTC (permalink / raw)
  To: help-gnu-emacs

On Jun 7, 10:35 am, Joost Kremers <joostkrem...@yahoo.com> wrote:
> Nikolaj Schumacher wrote:
> > On 2007-06-07, at 14:32, HippoMan wrote:
>
> >> During development of elisp code that I'm writing, I test regular
> >> expressions via the interactive use of M-x re-search-forward.  Once
> >> I've come up with a regexp that works, I often will want
> >> to yank it into my elisp code, for example, into a call to
> >> `match-string'.
>
> > Not really a solution for your specific problem, but I'd suggest
> > using `re-builder' for that.
>
> it can be a solution, though: re-builder supports different forms of input
> syntax. by default, it requires you to escape backslashes, so that when you
> type C-c C-w to copy the regexp to the kill-ring, you get it with every
> backslash escaped.
>
> if you don't want to type the double backslashes, you can change
> re-builders input syntax (with C-c TAB)from "read" to "string". then,
> before typing C-c C-w change it back again to "read": re-builder will
> automatically adjust the syntax and escape all backslashes for you.
>
> it's a pretty neat package, that re-builder.

Thank to all of you who suggested re-builder.  I can live with the
changing
of its input syntax from "read" to "string".  Hey, I might write my
own function(s)
for automating even this!

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

* Re: Converting a non-escaped regexp to an escaped version
  2007-06-07 15:12     ` HippoMan
@ 2007-06-07 15:19       ` Joost Kremers
  0 siblings, 0 replies; 8+ messages in thread
From: Joost Kremers @ 2007-06-07 15:19 UTC (permalink / raw)
  To: help-gnu-emacs

HippoMan wrote:
> Thank to all of you who suggested re-builder.  I can live with the
> changing of its input syntax from "read" to "string".  Hey, I might write
> my own function(s) for automating even this!

it may be possible to wrap reb-copy (the function called by C-c C-w in
re-builder) in a defadvice, so that it automatically changes the input
syntax for you before putting the regexp in the kill ring.


-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)

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

* Re: Converting a non-escaped regexp to an escaped version
@ 2007-06-07 21:25 martin rudalics
  0 siblings, 0 replies; 8+ messages in thread
From: martin rudalics @ 2007-06-07 21:25 UTC (permalink / raw)
  To: hippoman; +Cc: help-gnu-emacs

You could also have a look at a thing I wrote

http://lists.gnu.org/archive/html/gnu-emacs-sources/2005-11/msg00004.html

It has two commands which permit to find the next and previous match
for the regexp you are about to write in the same Elisp buffer.

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

* Re: Converting a non-escaped regexp to an escaped version
  2007-06-07 12:32 Converting a non-escaped regexp to an escaped version HippoMan
                   ` (2 preceding siblings ...)
       [not found] ` <mailman.1734.1181225695.32220.help-gnu-emacs@gnu.org>
@ 2007-06-11  9:31 ` Johan Bockgård
  3 siblings, 0 replies; 8+ messages in thread
From: Johan Bockgård @ 2007-06-11  9:31 UTC (permalink / raw)
  To: help-gnu-emacs

HippoMan <hippoman@gmail.com> writes:

> 1. Test a regular expression interactively, for example, via
>    the use of M-x re-search-forward.
>
> 2. Assume that I finally decide that the following regexp is
>    the one that I want to use within my elisp code:
>
>      \bfoo\b.*:.*\bbar\([0-9]\{9\}quack\.quack\)\b

3. C-x ESC ESC

-- 
Johan Bockgård

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

end of thread, other threads:[~2007-06-11  9:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-07 12:32 Converting a non-escaped regexp to an escaped version HippoMan
2007-06-07 14:14 ` Nikolaj Schumacher
2007-06-07 14:21 ` Juanma Barranquero
     [not found] ` <mailman.1734.1181225695.32220.help-gnu-emacs@gnu.org>
2007-06-07 14:35   ` Joost Kremers
2007-06-07 15:12     ` HippoMan
2007-06-07 15:19       ` Joost Kremers
2007-06-11  9:31 ` Johan Bockgård
  -- strict thread matches above, loose matches on Subject: below --
2007-06-07 21:25 martin rudalics

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