backreferences in PCRE?

Dave Cragg dcragg at lacscentre.co.uk
Thu Nov 13 17:10:46 EST 2003


At 2:15 pm -0700 13/11/03, Dar Scott wrote:

>Yikes.  I mean the negative assertion (?<!  ).  This should also 
>take care of the start.
>
>So tinker with this:
>
>replaceText(pStr, "(?<!\\)\\"&quote, "\"&quote)

Thanks for the pointer, Dar. It looks like this will do it.

   put "(?<!\\)" & quote into tRegEx
   replaceText(tStr, tRegEx, "\" & quote)
.
Although for this example, this might be easier:

   replace quote with "\" & quote in tStr
   replace "\\" & quote with "\" & quote in tStr

At 12:40 pm -0700 13/11/03, Alex Rice wrote:
>I can't remember- are any of Rev's REGEX functions capable of doing 
>backreferences?

Alex, it seems you can't backreference in the replacement expression 
as in Perl, but you can in the "find" expression, using "\1", "\2", 
etc.

In Perl, I don't think the $1, $2, etc. in the replacement expression 
are strictly regular expression  elements. They are really special 
Perl variables. For example, you can use $1 at anytime after a match 
and it will still hold the matched value.. However, it would be nice 
to have this ability in Rev, but I don't think $1, etc, would work as 
it would clash with Rev's environment variables.

Cheers
Dave



More information about the use-livecode mailing list