Hello,
have a script searching in input with
local s,e,msg = string.find(data, "%b<>%s+(.*)$")
This reacts to all inputs. I like to change it reacts only on #input. Trying
local s,e,msg = string.find(data, "%b<>%s+(%#.*)$")
or something like that (\035) failed. If I try an alpha char like
local s,e,msg = string.find(data, "%b<>%s+(%y.*)$")
it works fine. How to get this non alpha char # to work?
By the way, what's %b? Couldn't find anything about this.
Thanks for your help.
-BP-
%b<> is used to find anything within the "<>" like the nick .
Your code should work if its like this:
local s,e,msg = string.find(data, "%b<>%s+%#(.*)$")
unless u want it to show the # also.
the $ sign in your capturing is quite useless tho as $ indicates ( in this case ) "until the end of the string" while the capture (.*) also captures everything until the end
local s,e,msg = string.find(data, "%b<>%s+%#(.+)")
like Dessamator said, if you want the # included in the capturing it should work like
local s,e,msg = string.find(data, "%b<>%s+(%#.+)")
better try use the string.match instead of the .find ;)
compare:
local cmd = string.match( data, "%b<>%s+(%S+)" )
local s,e,cmd = string.find( data, "%b<>%s+(%S+)" )
You can make it even more advanced by doing following this principle:
("how many times?"):rep(15)
So that you have something like :
local cmd = data:match("%b<>%s+(%S+)")
Have fun!
Quote from: Herodes on 27 November, 2006, 12:40:21
local s,e,cmd = string.find( data, "%b<>%s+(%S+)" )
Isn't
string.find supposed to return the
s and
e values only?
Quote from: bastya_elvtars on 27 November, 2006, 13:17:39
Isn't string.find supposed to return the s and e values only?
Quote from: Lua5.1Manualstring.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 may 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.
<!--- notice the following part! -->
If the pattern has captures, then in a successful match the captured values are also returned, after the two indices.[/b]