lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On 2017-09-05 04:43 PM, Lev wrote:
Hi all,


I have some issues with string.find().

What do I miss?


$ lua5.3
Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio
str='--d8eb6ad5-707f-4518-8de9-0a339383199b--'
return string.find(str, '--d8eb6ad5-707f')
nil
return string.find(str, '--d8eb6ad5-')
1	9
return string.find(str, '--d8eb6ad5-7')
nil
I've tried that with 5.1, 5.2 and 5.3. All on Debian Stable, and also with 5.1 on some embedded platform on LEDE 17.01.1. Same result.


Any help welcome.

> return string.find(str, '--d8eb6ad5')
1    10

That's because - has a special meaning in Lua patterns:

http://www.lua.org/manual/5.3/manual.html#6.4.1

A pattern item can be

[...]
- a single character class followed by '-', which also matches zero or more repetitions of characters in the class. Unlike '*', these repetition items will always match the shortest possible sequence;



Thanks,
Levente


--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.