Possible Bug string.find

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible Bug string.find

Elio G.
Hi

I have Treo680 and TJX.

Plua2.0b8
-------------------------------------------
frase="bla bla (035-271426 )bla bla"
validi="1234567890-"

for i=1,string.len(frase),1 do
  le=string.sub(frase,i,i)
  rr = string.find(validi,le,1,plain) --->>> (ERROR Program.lua:7:unfinished
capture)
end -- for
------------------------------------------

frase="bla bal (030-271426 )bla bla"
validi="1234567890-"

for i=1,string.len(frase),1 do
  le=string.sub(frase,i,i)
  if le=="(" then le="a" end
  rr = string.find(validi,le,1,plain) -->>>> OK!>>>>>>
end -- for

It is BUGS ?? string.find() +"(" ?????

Thanks for Plua.
Reply | Threaded
Open this post in threaded view
|

Re: Possible Bug string.find

migueletto
Hi,

--- In [hidden email], "Elio G." <besne@...> wrote:

> frase="bla bla (035-271426 )bla bla"
> validi="1234567890-"
>
> for i=1,string.len(frase),1 do
>   le=string.sub(frase,i,i)
>   rr = string.find(validi,le,1,plain) --->>> (ERROR
Program.lua:7:unfinished
> capture)
> end -- for
>
> It is BUGS ?? string.find() +"(" ?????

A "(" inside a pattern has a special meaning: it starts a capture, and
each capture must be closed with a ")". Please refer to section 5.3 of
the Lua 5.0 manual, under the section "Patterns".

If you want to search for plain strings instead of patterns, use this:

rr = string.find(validi,le,1,true)

Regards,
Marcio.