[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rx vs sregex - a "match" to the death

From: Martin Stone Davis
Subject: Re: rx vs sregex - a "match" to the death
Date: Mon, 06 Oct 2003 01:41:13 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20030925

Oliver Scholz wrote:

Martin Stone Davis <> 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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]