Re: wildcard_match question
- Posted by Pete Lomax <petelomax at blueyon?er.co.uk> Jul 08, 2007
- 513 views
Salix wrote: > > > }}} <eucode> > include wildcard.e > ? wildcard_match("*ema*l*"," the email address") > ? wildcard_match("*ema*l*","* the email address") > </eucode> {{{ > > Is it meant to work like this? I thought string st2 ("* the email address") > matches pattern st1 ("*em*l*") in the second case. > I took a quick look at this. What is happening is that the * in st2 is being treated as a literal match against the first * in st1, and hence that first * is no longer treated as a wildcard. I noted that
? wildcard_match("*ema*l*","*email address")
prints 1 because st1 and st2 begin with the literal "*ema". I also tried:
? wildcard_match("*ema*l*"," *the email address")
which also prints 1, so obviously a * in st2 does not have to literally match and "absorb" a * in st1. I haven't tested this properly, but I think the following might fix it - any comments Rob? In wildcard_match(), replace
if not find(pattern[p], {str[f], '?'}) then
with
integer pp pp = pattern[p] if pp='*' or (pp!=str[f] and pp!='?') then
or possibly, since the routine appears as if it would work with complex nested sequences as well as plain character strings (and why not):
object pp pp = pattern[p] if equal(pp,'*') or (not equal(pp,str[f]) and not equal(pp,'?')) then
Regards, Pete