unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Storing regular expressions somewhere....
@ 2006-08-23 14:05 Birju Prajapati
  2006-08-23 15:10 ` Birju Prajapati
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Birju Prajapati @ 2006-08-23 14:05 UTC (permalink / raw)


Hi all,
Sometimes I need to do complicated replace-regexps. However, they can
be prone to errors, so what I end up doing is an
isearch-forward-regexp until I get the expression correct. Once it is
correct, I write it down and then type it back into a replace-regexp
command! Rather cumbersome....Is there some sort of
isearch-forwared-replace-regexp command ? Or can I recall the previous
regexp searched for in my isearch-forward-regexp?

TIA
Birju

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

* Re: Storing regular expressions somewhere....
  2006-08-23 14:05 Storing regular expressions somewhere Birju Prajapati
@ 2006-08-23 15:10 ` Birju Prajapati
  2006-08-23 15:27 ` Drew Adams
       [not found] ` <mailman.5508.1156345825.9609.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 5+ messages in thread
From: Birju Prajapati @ 2006-08-23 15:10 UTC (permalink / raw)


On 23/08/06, Birju Prajapati <floating.buddha@gmail.com> wrote:
> Hi all,
> Sometimes I need to do complicated replace-regexps. However, they can
> be prone to errors, so what I end up doing is an
> isearch-forward-regexp until I get the expression correct. Once it is
> correct, I write it down and then type it back into a replace-regexp
> command! Rather cumbersome....Is there some sort of
> isearch-forwared-replace-regexp command ? Or can I recall the previous
> regexp searched for in my isearch-forward-regexp?

After digging around a bit, I found M-x regexp-builder. However, this
doesn't seem to understand predefined character classes such as \s-
and seems to have a different regexp syntax. Is this a bug or am I
doing something wrong?

Cheers,
Birju

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

* RE: Storing regular expressions somewhere....
  2006-08-23 14:05 Storing regular expressions somewhere Birju Prajapati
  2006-08-23 15:10 ` Birju Prajapati
@ 2006-08-23 15:27 ` Drew Adams
       [not found] ` <mailman.5508.1156345825.9609.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2006-08-23 15:27 UTC (permalink / raw)


    Sometimes I need to do complicated replace-regexps. However, they can
    be prone to errors, so what I end up doing is an
    isearch-forward-regexp until I get the expression correct. Once it is
    correct, I write it down and then type it back into a replace-regexp
    command! Rather cumbersome....Is there some sort of
    isearch-forwared-replace-regexp command ? Or can I recall the previous
    regexp searched for in my isearch-forward-regexp?

You might want to take a look at Icicles, which lets you use `C-=' to recall
a string (e.g. a regexp) that you've saved in a variable, into the
minibuffer later as input. Here's an explanation:

http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_Inserting_a_Regexp_from_a_Va
riable

HTH.

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

* Re: Storing regular expressions somewhere....
       [not found] ` <mailman.5508.1156345825.9609.help-gnu-emacs@gnu.org>
@ 2006-08-23 15:45   ` Johan Bockgård
  0 siblings, 0 replies; 5+ messages in thread
From: Johan Bockgård @ 2006-08-23 15:45 UTC (permalink / raw)


"Birju Prajapati" <floating.buddha@gmail.com> writes:

> On 23/08/06, Birju Prajapati <floating.buddha@gmail.com> wrote:
>> Hi all,
>> Sometimes I need to do complicated replace-regexps. However, they
>> can be prone to errors, so what I end up doing is an
>> isearch-forward-regexp until I get the expression correct. Once it
>> is correct, I write it down and then type it back into a
>> replace-regexp command! Rather cumbersome....Is there some sort of
>> isearch-forwared-replace-regexp command ? Or can I recall the
>> previous regexp searched for in my isearch-forward-regexp?

You can type `M-e' in isearch and then copy the string from there.

(In Emacs 22 you can run query replace directly from isearch with
`M-%'.)

Also, if you set `query-replace-interactive' to non-nil, replacements
will reuse the last search string automatically.

> After digging around a bit, I found M-x regexp-builder. However,
> this doesn't seem to understand predefined character classes such as
> \s- and seems to have a different regexp syntax. Is this a bug or am
> I doing something wrong?

By default backslashes have to be doubled (like inside a Lisp string).
Try

  (setq reb-re-syntax 'string)

-- 
Johan Bockgård

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

* RE: Storing regular expressions somewhere....
@ 2006-08-23 18:29 Jay Bingham
  0 siblings, 0 replies; 5+ messages in thread
From: Jay Bingham @ 2006-08-23 18:29 UTC (permalink / raw)


On Wednesday, 23 August 2006 Birju Prajapati wrote:

> After digging around a bit, I found M-x regexp-builder. However, 
this
> doesn't seem to understand predefined character classes such as \s-
> and seems to have a different regexp syntax. Is this a bug or am I
> doing something wrong?

First, I assume that when you say regexp-builder your are actually 
referring to re-builder.el.
Although I am not an re-builder guru, I have used it quite a bit and 
I found it hard to believe that it did not understand the predefined 
character classes, so I tried it.  It works for me so you must be 
doing something wrong. ;-)

Before we get to what you could be doing wrong lets talk about what 
you mean when you say that it has a different regexp syntax.  Do you 
mean that in the default input syntax, escape characters 
(backslashes) must be doubled and double quotes must be escaped, 
which means that regular expressions generated with this syntax 
cannot be used in the interactive commands: isearch-forward-regexp, 
query-replace-regexp and replace-regexp?

Carefully reading of the commentary in re-builder reveals that there 
are four forms of input syntax provided by re-builder:
 'read', 'string', 'sregex' and 'lisp-re'
The default input syntax form is: 'read'
The syntax used by the 'read' form is the syntax that is used in the 
arguments of functions like re-search-forward and re-search-backward, 
which are used when an e-lisp function that does searching is 
written.  This syntax requires that escape characters and double 
quotes be escaped.
The syntax used by the 'string' form is the syntax that is used by 
the interactive functions isearch-forward-regexp, query-replace-
regexp and replace-regexp.
As stated in the commentary, "With the `string' syntax there's no 
need to escape the backslashes and double quotes simplifying the 
editing somewhat."  
Regarding the other two input forms the commentary states: "The other 
two allow editing of symbolic regular expressions supported by the 
packages of the same name.  (`lisp-re' is a package by me and its 
support may go away as it is nearly the same as the `sregex' package 
in Emacs)."  (I am not familiar with either of these packages and I 
don't believe that they pertain to your situation so that is all that 
will be said about them).

Now that we have that out of the way, I suspect that what you were 
doing wrong was trying to use 'string' syntax in 'read' syntax mode.

Here is a regexp that I created while reading the re-builder 
commentary after changing to string syntax (C-c C-i string RET):
 c\sw+?\(r\|w\)\w+\s-
It matches 31 strings and the space that follows them in the re-
builder.el file.
This regexp matches 268 words and the space that follows them in the 
re-builder.el file:
 \b\sw+?\(r\|w\)\w+\s-

With the above regexp in the RE-Builder buffer when I change 
from 'string' to 'read' syntax the regexp changes to the following:
\\b\\sw+?\\(r\\|w\\)\\w+\\s-
Changing back to 'string' syntax restores the regexp to its former 
value.

Good luck and thanks for the opportunity to learn more about re-
builder.
__
J_)
C_)ingham 


_____________________________________________________________________
PrivatePhone - FREE telephone number & voicemail.
A number so private, you can make it public.
http://www.privatephone.com

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

end of thread, other threads:[~2006-08-23 18:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-23 14:05 Storing regular expressions somewhere Birju Prajapati
2006-08-23 15:10 ` Birju Prajapati
2006-08-23 15:27 ` Drew Adams
     [not found] ` <mailman.5508.1156345825.9609.help-gnu-emacs@gnu.org>
2006-08-23 15:45   ` Johan Bockgård
  -- strict thread matches above, loose matches on Subject: below --
2006-08-23 18:29 Jay Bingham

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