Jump to content




string.find with (


  • You cannot reply to this topic
3 replies to this topic

#1 Wilma456

  • Members
  • 187 posts
  • LocationGermany

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?

#2 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 28 November 2016 - 07:43 PM

Because brackets are a special character in patterns you have to escape them.

("test()"):find "%("


#3 Cross_Sans

  • Members
  • 122 posts
  • LocationFrance

Posted 04 December 2016 - 01:49 PM

View PostH4X0RZ, on 28 November 2016 - 07:43 PM, said:

...

Please do not forgot the brackets, because this is correct, but pretty dirty:
("test()"):find("%(");
or
string.find("test()", "%(");

Edited by Redall, 04 December 2016 - 01:51 PM.


#4 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 04 December 2016 - 04:25 PM

View PostRedall, on 04 December 2016 - 01:49 PM, said:

View PostH4X0RZ, on 28 November 2016 - 07:43 PM, said:

...

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users