PtokaX forum

Archive => Archived 5.1 boards => Help with scripts => Topic started by: BluePanther on 27 November, 2006, 11:41:25

Title: Question about string.find(
Post by: BluePanther on 27 November, 2006, 11:41:25
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-
Title: Re: Question about string.find(
Post by: Dessamator on 27 November, 2006, 12:08:05
%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.
Title: Re: Question about string.find(
Post by: CrazyGuy on 27 November, 2006, 12:34:44
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+(%#.+)")
Title: Re: Question about string.find(
Post by: Herodes on 27 November, 2006, 12:40:21
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!
Title: Re: Question about string.find(
Post by: bastya_elvtars on 27 November, 2006, 13:17:39
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?
Title: Re: Question about string.find(
Post by: Herodes on 27 November, 2006, 14:06:57
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]