This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Wilma456's profile picture

string.find with (

Started by Wilma456, 28 November 2016 - 06:33 PM
Wilma456 #1
Posted 28 November 2016 - 07:33 PM
If I write string.find("test()","("), it give me the error "unfinished capture". Other Chars work. what can I do?
H4X0RZ #2
Posted 28 November 2016 - 07:43 PM
Because brackets are a special character in patterns you have to escape them.


("test()"):find "%("
Cross_Sans #3
Posted 04 December 2016 - 01:49 PM

Please do not forgot the brackets, because this is correct, but pretty dirty:

("test()"):find("%(");
or

string.find("test()", "%(");
Edited on 04 December 2016 - 12:51 PM
H4X0RZ #4
Posted 04 December 2016 - 04:25 PM

Please do not forgot the brackets, because this is correct, but pretty dirty:

("test()"):find("%(");
or

string.find("test()", "%(");

That's "normal" Lua syntax. I don't see a reason why you should add brackets if you don't have to; You save time and space. In contrast, your code is "dirty": You are using semicola even though they have no "special" meaning in Lua. They are just there to comfort those who come from languages enforcing them so their habits won't break their code.