* rx vs sregex - a "match" to the death
@ 2003-10-05 12:07 Martin Stone Davis
0 siblings, 0 replies; 6+ messages in thread
From: Martin Stone Davis @ 2003-10-05 12:07 UTC (permalink / raw)
Who likes `rx'?
Who likes `sregex'?
Who likes `rx' more than `sregex'?
Who likes `sregex' more than `rx'?
Why?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: rx vs sregex - a "match" to the death
[not found] <mailman.1134.1065355880.21628.help-gnu-emacs@gnu.org>
@ 2003-10-05 15:45 ` Oliver Scholz
2003-10-05 17:08 ` Martin Stone Davis
[not found] ` <mailman.1139.1065373803.21628.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 6+ messages in thread
From: Oliver Scholz @ 2003-10-05 15:45 UTC (permalink / raw)
Martin Stone Davis <m0davis@pacbell.net> writes:
> Who likes `rx'?
> Who likes `sregex'?
> Who likes `rx' more than `sregex'?
> Who likes `sregex' more than `rx'?
> Why?
>From the commentary section of rx.el:
This is another implementation of sexp-form regular expressions.
It was unfortunately written without being aware of the Sregex
package coming with Emacs, but as things stand, Rx completely
covers all regexp features, which Sregex doesn't, doesn't suffer
from the bugs mentioned in the commentary section of Sregex, and
uses a nicer syntax (IMHO, of course :-).
Personally I don't know about the nicer syntax, because I never tried
sregex. For the very reason that I discovered rx first.
Oliver
--
14 Vendémiaire an 212 de la Révolution
Liberté, Egalité, Fraternité!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: rx vs sregex - a "match" to the death
2003-10-05 15:45 ` rx vs sregex - a "match" to the death Oliver Scholz
@ 2003-10-05 17:08 ` Martin Stone Davis
[not found] ` <mailman.1139.1065373803.21628.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 6+ messages in thread
From: Martin Stone Davis @ 2003-10-05 17:08 UTC (permalink / raw)
Oliver Scholz wrote:
> Martin Stone Davis <m0davis@pacbell.net> writes:
>
>
>>Who likes `rx'?
>>Who likes `sregex'?
>>Who likes `rx' more than `sregex'?
>>Who likes `sregex' more than `rx'?
>>Why?
>
>
>>From the commentary section of rx.el:
>
> This is another implementation of sexp-form regular expressions.
> It was unfortunately written without being aware of the Sregex
> package coming with Emacs, but as things stand, Rx completely
> covers all regexp features, which Sregex doesn't, doesn't suffer
> from the bugs mentioned in the commentary section of Sregex, and
> uses a nicer syntax (IMHO, of course :-).
>
> Personally I don't know about the nicer syntax, because I never tried
> sregex. For the very reason that I discovered rx first.
>
> Oliver
Thanks for pointing that out. I should have thought to read there.
While I was comparing the two functions, I could not find if/how rx
handles numbered backreferences. It's done in sregex like this:
;; (sregexq (group (or "Go" "Run"))
;; ", Spot, "
;; (backref 1)) => "\\(Go\\|Run\\), Spot, \\1"
How do you do the same using rx?
I should also mention that sregex does not try to optimize `or'
constructs. rx automatically runs regexp-opt on any (or ...) it sees.
-Martin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: rx vs sregex - a "match" to the death
[not found] ` <mailman.1139.1065373803.21628.help-gnu-emacs@gnu.org>
@ 2003-10-06 7:25 ` Oliver Scholz
2003-10-06 8:41 ` Martin Stone Davis
[not found] ` <mailman.1154.1065429721.21628.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 6+ messages in thread
From: Oliver Scholz @ 2003-10-06 7:25 UTC (permalink / raw)
Martin Stone Davis <m0davis@pacbell.net> writes:
[...]
> While I was comparing the two functions, I could not find if/how rx
> handles numbered backreferences. It's done in sregex like this:
>
> ;; (sregexq (group (or "Go" "Run"))
> ;; ", Spot, "
> ;; (backref 1)) => "\\(Go\\|Run\\), Spot, \\1"
>
> How do you do the same using rx?
[...]
Well, you could use (regexp "\\1"), but this is of course not
satisfying. I am not aware of any other way to use backrefs with `rx'.
However, I was not aware that you actually can use backrefs within a
regexp. I tried
(progn (looking-at "\\w+")
(forward-char 1)
(re-search-forward "\\0" nil t))
But that did not lead to the result that you would expect if backrefs
are/were supported within regexps.
Could you provide an example where this is meaningful?
Oliver
--
15 Vendémiaire an 212 de la Révolution
Liberté, Egalité, Fraternité!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: rx vs sregex - a "match" to the death
2003-10-06 7:25 ` Oliver Scholz
@ 2003-10-06 8:41 ` Martin Stone Davis
[not found] ` <mailman.1154.1065429721.21628.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 6+ messages in thread
From: Martin Stone Davis @ 2003-10-06 8:41 UTC (permalink / raw)
Oliver Scholz wrote:
> Martin Stone Davis <m0davis@pacbell.net> writes:
> [...]
>
>>While I was comparing the two functions, I could not find if/how rx
>>handles numbered backreferences. It's done in sregex like this:
>>
>>;; (sregexq (group (or "Go" "Run"))
>>;; ", Spot, "
>>;; (backref 1)) => "\\(Go\\|Run\\), Spot, \\1"
>>
>>How do you do the same using rx?
>
> [...]
>
> Well, you could use (regexp "\\1"), but this is of course not
> satisfying. I am not aware of any other way to use backrefs with `rx'.
>
> However, I was not aware that you actually can use backrefs within a
> regexp. I tried
>
> (progn (looking-at "\\w+")
> (forward-char 1)
> (re-search-forward "\\0" nil t))
>
> But that did not lead to the result that you would expect if backrefs
> are/were supported within regexps.
>
> Could you provide an example where this is meaningful?
I think you're using backreference wrongly. Try the one I gave.It
matches "Go, Spot, Go" OR "Run, Spot, Run". If I run
(re-search-forward (sregexq (group (or "Go" "Run"))
", Spot, "
(backref 1))
It finds either of those two phrases.
-Martin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: rx vs sregex - a "match" to the death
[not found] ` <mailman.1154.1065429721.21628.help-gnu-emacs@gnu.org>
@ 2003-10-06 8:55 ` Oliver Scholz
0 siblings, 0 replies; 6+ messages in thread
From: Oliver Scholz @ 2003-10-06 8:55 UTC (permalink / raw)
Martin Stone Davis <m0davis@pacbell.net> writes:
[backrefs in regexps]
> I think you're using backreference wrongly. Try the one I gave.
<forehead-slap/>
Silly me.
> It matches "Go, Spot, Go" OR "Run, Spot, Run". If I run
>
> (re-search-forward (sregexq (group (or "Go" "Run"))
> ", Spot, "
> (backref 1))
>
> It finds either of those two phrases.
[...]
Thanks. That's nifty.
Oliver
--
15 Vendémiaire an 212 de la Révolution
Liberté, Egalité, Fraternité!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2003-10-06 8:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.1134.1065355880.21628.help-gnu-emacs@gnu.org>
2003-10-05 15:45 ` rx vs sregex - a "match" to the death Oliver Scholz
2003-10-05 17:08 ` Martin Stone Davis
[not found] ` <mailman.1139.1065373803.21628.help-gnu-emacs@gnu.org>
2003-10-06 7:25 ` Oliver Scholz
2003-10-06 8:41 ` Martin Stone Davis
[not found] ` <mailman.1154.1065429721.21628.help-gnu-emacs@gnu.org>
2003-10-06 8:55 ` Oliver Scholz
2003-10-05 12:07 Martin Stone Davis
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).