mIRC Homepage

Regex help

Posted By: RuLerZ

Regex help - 02/05/13 04:53 AM

Hello I am currently creating a polling system and it is working fine right now using !poll option1 option2 option3 creating 3 different poll options but if I mess up and do something like !poll option 1 option 2 option 3 it will create 6 poll options.
I have been trying to make it so you can include spaces and between every comma is a different option
EX: !poll option 1, option 2, option 3
which should return 3.

I am currently doing this: $regex($2-,/\b\w+\b/g)
Thank you for any help you can provide.
Posted By: Riamus2

Re: Regex help - 02/05/13 10:20 AM

Although you can use regex, it may be easier to just tokenize it.

Code:
on *:text:!poll *:#:{
  tokenize 44 $2-
  var %option1 = $1
  var %option2 = $2
  var %option3 = $3
}


Of course, you can shorten that and adjust it as needed. That's just an example with everything spread out so it's easy to see and understand. Also, if you are typing it on the same client as the script, you'd want to make that an on INPUT event instead, but the rest is the same.
Posted By: RuLerZ

Re: Regex help - 02/05/13 03:10 PM

Thank you very much for the quick response. That will do exactly what I needed to do to get the different poll options just needed to make a bunch of if statements to find the total poll options lol. Thank you so much!!
Posted By: Deega

Re: Regex help - 02/05/13 11:55 PM

Originally Posted By: RuLerZ
just needed to make a bunch of if statements to find the total poll options lol. Thank you so much!!

$0 will give you the number of options.
Code:
on *:text:!poll *:#:{
  tokenize 44 $2-
  var %options = $0
  var %option1 = $1
  var %option2 = $2
  var %option3 = $3
}
Posted By: Riamus2

Re: Regex help - 03/05/13 10:14 AM

As Deega mentioned, you can use $0. Just to expand on that, 0 is used in many places in mIRC to get the total number of something. So anytime you are looking for a count for a given identifier, try replacing the item number with 0 and in most cases it will give you the total.
Posted By: RuLerZ

Re: Regex help - 10/05/13 11:57 PM

Aww sweet!!! Ty so much made the code so much cleaner! you guys rock!!
© 2020 mIRC Discussion Forums