egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

regexp help

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
ukd4v1d
Voice


Joined: 01 Feb 2009
Posts: 2

PostPosted: Sat Jan 14, 2012 5:51 am    Post subject: regexp help Reply with quote

I'm having a little trouble getting regexp to pick up what i want from txt in channel
I've shaped a script to capture data spoken in channel to add to an SQL Database. There are different types of lines im looking to capture but my code is only picking up partial data.

My ever growing list of FAQ's and Game Walkthroughs are shared via X**C Bots either ran from my server or from writers own mIRC Scripts

Sample Data and code can be seen here
http://pastebin.com/4tB6AQK8

Any help would greatly be appreciated
Thanks
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Tue Jan 17, 2012 12:09 pm    Post subject: Reply with quote

The best way to check simple regular expressions is to use test data in a command line Tcl shell. If
you have enabled tcl/set commands in the bot's .conf file then this can be done on the party line.

As an example

1. Define the regular expression pattern as per the first such statement in your code
.tcl set regexp {^XDCC Server Active Sends:«(.*?)» Queues:«(.*?)» *$}
Tcl: ^XDCC Server Active Sends:?(.*?)? Queues:?(.*?)? *$

2. Execute the regular expression using the corresponding test data you provided
.tcl regexp -nocase -- $regexp "XDCC Server Active Sends:«0/3» Queues:«0/50»" -> OpenSlots
Tcl: 1

3. Check the value of the captured variable
.tcl set OpenSlots
Tcl: 0/3

Note that you have defined two capture groups with the parenthesis in your regular expression pattern, but
only one captured variable in the actual regular expression. All is well if you want the text from the first
capture group. ie. OpenSlots == Active Sends. If however you want the second capture group then you could
possibly redefine your regular expression as follows, with two captured variables (one a dummy only)

.tcl regexp -nocase -- $regexp "XDCC Server Active Sends:«0/3» Queues:«0/50»" -> dummy OpenSlots
Tcl: 1

.tcl set OpenSlots
Tcl: 0/50

Sorry I can't be more specific regarding possible errors elsewhere, I just wanted to give you a way of solving
your own problem. I think I can safely say I rarely define a regular expression that works first time. These
command line tools are a necessity for me.
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber