Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does lua string.find return true for this test case?

Tags:

string

lua

I'm just new to lua... and so I apologize if i'm missing something basic.
i'm running a simple test to see if i can find certain values in a string.

Here's the code:

print(string.find('fd@testca','.') )

Instead of failing, which is what I was expecting, I'm getting back:

mymachinename:/usr/share/std/test# lua test.lua
1       1

Can you tell me where I'm going wrong? Thanks.

like image 447
dot Avatar asked Mar 07 '13 16:03

dot


1 Answers

This is because in Lua the find method looks for a pattern, and . represents any character.

You can use character sets to work around the problem:

print(string.find('fd@testca','[.]') )

Here is a link to a small demo.

like image 114
Sergey Kalinichenko Avatar answered Nov 03 '22 00:11

Sergey Kalinichenko