Main Menu
  • Welcome to The RPG Maker Resource Kit.

[Lua]Regular Expression Help !

Started by ahref, April 16, 2009, 04:46:14 PM

0 Members and 1 Guest are viewing this topic.

ahref

Hi there. Im writing an irc bot and am having to use regular expressions everywhere to wade through the crap that is RAW IRC. I have found a few patterns online that split stuff down nicely. I however cannot find or stumble uppon a regular expression or group of regular expressions that will return the data i need from the following line:
ahref ahref :+#thc %#crankeye

Lua doesn't actually call its pattern matching regular expressions but its practically the same eg.:

prefix, cmd, param = string.match(p, "^:([^ ]+) ([^ ]+)(.*)$")


splits a line into its base parts eg. ":ahref!~ahref@FDC777BF.FFB88ACD.E46257AB.IP PRIVMSG #THC :cowbot" to
prefix = ahref!~ahref@FDC777BF.FFB88ACD.E46257AB.IP
cmd = PRIVMSG
param = #THC :cowbot

what i need from:
ahref ahref :~#thc %#crankeye
is just a simple
user = ahref
modes = ~(im only interested in modes on "#thc")

anyone got any ideas :D?

EDIT: i can now get the FIRST nickname with " ([%w]+)" but i want the second.

EDIT4: got them both first one seems a bit hacky but meh
         nick = string.match(param,"[%w] ([%w]+)")
         modes = string.match(param, "([+%%~&@])#thc")

tSwitch

I don't think anyone else uses lua


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

ahref

:( You make me sad. its a nice language :D