[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Understanding Strings
- From: Eike Decker <zet23t@...>
- Date: Mon, 28 May 2012 22:51:56 +0200
>
> You need to escape the paren:
>
> your_string:find("%(")
Alternatively, pass true as 4th argument, from the docs:
---
string.find (s, pattern [, init [, plain]])
Looks for the first match of pattern in the string s. If it finds a
match, then find returns the indices of s where this occurrence starts
and ends; otherwise, it returns nil. A third, optional numerical
argument init specifies where to start the search; its default value
is 1 and can be negative. A value of true as a fourth, optional
argument plain turns off the pattern matching facilities, so the
function does a plain "find substring" operation, with no characters
in pattern being considered "magic". Note that if plain is given, then
init must be given as well.
If the pattern has captures, then in a successful match the captured
values are also returned, after the two indices.
---
So when you only want to search for a substring, use the "plain"
argument to search more efficiently and moreover, without the need to
escape anything.
Cheers,
Eike