Bug? dots in starts/ends-with

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Bug? dots in starts/ends-with

Post by newdep »

Hi Lutz,

We have a "DOT" bugging around in starts-with and ends-with.. ;-)

Something realy funny is going on here...

> (starts-with "ohno!" "oh" 1)
true

> (starts-with "ohno!" "oh." 1)
true

> (starts-with "ohno!" "Yes|oh." 1)
true

> (starts-with ".ohno!" "." )
true

> (starts-with ".ohno!" "." 1)
true

> (ends-with "ohno." "." 1)
nil

> (ends-with "ohno." ".")
true



Norman.
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

the dot in a regular expression means 'any character'. Except for the second to last one where I am not sure, they are all correct.

Lutz

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

If you are checking for a dot as the last character with a regular expression you would do:

Code: Select all

(ends-with "ohno." "\\." 0) => true
Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

aha oke... Then i think the documentation should be a little adjusted from the
string part on starts-with and ends-with..

because i was under the impression that only for lists the regex where possible..
and that the "....|....." was a hardcoded "or"..

but indeed this one bothers me and thats the one im fighting all day now..

> (ends-with "ohno." "." 1)
nil


Norman.
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Aggg those regex kill me... ;-)

double \\ man...i was hitting \. all day...


Its time for some logic inside regex ;-) (for the none regex manual reading kind of programmer)
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

... but there is indeed a problem, which will be fixed in 9.1.7.

As a workaround when using regex in 'ends-with' always anchor the regulare expression to the end:

Code: Select all

(ends-with "onhno." ".$" 1) => true
now it works correctly

Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Mmmm its not the solution.... the '.$" removes everything from my lists ;-)
Ill have to do it differently for now...

Thanks...

Norman.
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

if you want to detect an ending dot you really should use:

Code: Select all

(ends-with xyz "\\.$" 0)
and not

Code: Select all

(ends-with xyz ".$" 0)
which would fire on any string in xyz

The anchoring bug is fixed in 9.17.tgz but don't want to relase until the GUI stuff is done in a few days. If this is an urgent problem I can release the 9.1.7 version earlier. But including '$' at the end of the regex string really should take care of your problem.

what regex pattern are you looking for? perhaps we can help you there?

Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

you are early awake ;-)

I can life with the '." for now I do some manual cleaning on the list
every now and then... Im doing some webstatistics ;-) durrently the
list is between 150.000 and 80.000 entry's and the regex im using is
cleaning data.. its oke for now.. Ill hope to finetune and release this tool
(yes it becoming a tool ;-) in GUI format...;-)

Norman.
-- (define? (Cornflakes))

Locked