Question about string.find(
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Question about string.find(

Started by BluePanther, 27 November, 2006, 11:41:25

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

BluePanther

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-

Dessamator

%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.
Ignorance is Bliss.

CrazyGuy

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+(%#.+)")

Herodes

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!

bastya_elvtars

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?
Everything could have been anything else and it would have just as much meaning.

Herodes

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]

SMF spam blocked by CleanTalk