This is the new home of the community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.

For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

regexp help

Help for those learning Tcl or writing their own scripts.
Post Reply
Posts: 2
Joined: Sun Feb 01, 2009 3:13 pm

regexp help

Post by ukd4v1d »

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

Any help would greatly be appreciated
User avatar
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

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
Post Reply