NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
backreference in regex replace with lookahead/lookbehind bug
Veteran

Joined: 30 Aug 2006
Posts: 116
Reply with quote
Hi there,

I believe there's a possible bug with regex replaces that use backreference when the regex contains lookahead/lookbehind.

What I'm attempting to do is find all instances of & in a URL and replace it with & for w3c compliance.

The regex I came up with is:

(?<=[\w])&((?!amp;|nbsp;)[\w$]+?)(?==)

the replace sequence I use is:

&amp;\1

The result is that the replace actually literally inserts:

&amp;\1.

For instance in the string:

http://mywebsite/index.php?id=1&f=3

the result is:

http://mywebsite/index.php?id=1&amp\1=3


PS. Perhaps my regex sucks, but I know for sure regex coach (http://weitz.de/regex-coach/) confirms my regex should be working fine. I know the regex is capable of matching the & because I have tested replaces without the backreference and they work fine.
View user's profileFind all posts by rudderSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
yep, looks like something with regexp.
I just tried some simple ones and they worked fine.
What regexps we support are based on PCRE 4.5 library.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
After a little investigation it appeared that regexp library we use works fine. The problem was in our wrapping stuff and it's fixed by now and your sample gets:
http://mywebsite/index.php?id=1f=f=3
as it should (\0 contains &f and \1 contains f).

Fix will be available in a next few days.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Aug 2006
Posts: 116
Reply with quote
This is great news!! Very Happy
View user's profileFind all posts by rudderSend private message
backreference in regex replace with lookahead/lookbehind bug
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic