Page 1 of 1

[Help] Bug? String.find does not match dashes

Posted: Sat Jan 09, 2016 11:58 pm
by SilverDragon
Either it's a bug, or just a feature that's missing/was never implemented, but string.find will not (can't?) match on dashes. I've tested and it matches every other common special/grammatical character I could think of(quotes, commas, semi-colons, colons, apostrophes, periods, backslashes, forwardslashes, straight slashes, underscore, parentheses....I stopped testing after parentheses)

I tested it with the following code to confirm.
Code: [show] | [select all] lua
testing = {'samwise "the gardener" gamgee', "Daerlain, an elderly noblewoman", "a keen-eyed archer", "tick;tock", "rat:fink", " much ado 'bout nothing", "dr. pepsi", "green\blue", "red/orange", "white|black", "magick_magic", "(svo)"} 

denizen = "a keen-eyed archer"

for k,v in ipairs(testing) do
	if v:find(denizen) then
		echo("\n denizen found \n")
		break
	end -- if
end -- for
Does anyone know of a function that performs the same as string.match, but will match on dashes?

or alternatively, who/how do I report this to the mudlet Devs as a potential bug?

Thanks.

()()
(..)
(")(")

Re: [Help] Bug? String.find does not match dashes

Posted: Sun Jan 10, 2016 9:35 pm
by Belgarath
If you want to match a dash with string.find/match, you'll need to add % beforehand so it escapes it since it's a special character. %w+ vs %w- is that + is greedy, - isn't.

Re: [Help] Bug? String.find does not match dashes

Posted: Fri Mar 04, 2016 5:24 pm
by SilverDragon
that worked, but I also found (courtesy of: http://lua-users.org/wiki/StringLibraryTutorial) that doing

Code: Select all

for k,v in ipairs(testing) do
        if v:find(denizen, 1, true) then --- Changed to plain search
                echo("\n denizen found \n")
                break
        end -- if
end -- for
Works brilliantly too. :)