RE: Storing regular expressions somewhere....

From:

Jay Bingham

Subject:

RE: Storing regular expressions somewhere....

Date:

Wed, 23 Aug 2006 18:29:06 GMT

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