You are here: PSPad forum > English discussion forum > regular expression matching bug?

regular expression matching bug?

#1 regular expression matching bug?

Posted by: luweitest | Date: 11/16/2011 10:19 | IP: IP Logged

PSpad 4.5.6 2427
When replacing <c r=".+?"[^>]+?/> ,
<c r="A4" s="24" t="s"><v>17</v></c><c r="B4" s="25"/> was matched instead of my expectation that only <c r="B4" s="25"/> should be matched. What can I do?

Options: Reply | Quote | Up ^


#2 Re: regular expression matching bug?

Posted by: vbr | Date: 11/16/2011 11:34 | IP: IP Logged

luweitest:
PSpad 4.5.6 2427
When replacing <c r=".+?"[^>]+?/> ,
<c r="A4" s="24" t="s"><v>17</v></c><c r="B4" s="25"/> was matched instead of my expectation that only <c r="B4" s="25"/> should be matched. What can I do?

I believe, it is an expected matching behaviour, I guess even the non-greedy quantifiers don't move the start of the match forward, if a valid match can be found. (The regex continues to match as early as possible and only the further extent of the match depends on greedeness.)

You could restrict the likely "attribute" pattern a bit ".+?"
i.e. like
<c r="[^>]+?"[^>]+?/>
<c r="[^>]+?"[^"]+?/>
if it suits your data.
Both of them match as you seem to prefer in this example.

hth,
vbr

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2013 Jan Fiala
Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák