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

Post Reply
SilverDragon
Posts: 23
Joined: Tue Mar 01, 2011 10:00 pm

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

Post by SilverDragon » Sat Jan 09, 2016 11:58 pm

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.

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

User avatar
Belgarath
Posts: 232
Joined: Fri Jul 26, 2013 7:19 am
Discord: macjabeth#2283

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

Post by Belgarath » Sun Jan 10, 2016 9:35 pm

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.

SilverDragon
Posts: 23
Joined: Tue Mar 01, 2011 10:00 pm

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

Post by SilverDragon » Fri Mar 04, 2016 5:24 pm

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. :)

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests