mIRC Homepage
Posted By: vexed Regex question - 29/10/06 07:12 PM
I have this as part of a stats bot to pick up smilies

Code:
$calc($regex($1-,/(\:|;)(-)?(P|X|D|\/|\\|\[|\])/ig) + $count($1-,: $+ $chr(40),:- $+ $chr(40),: $+ $chr(41),:- $+ $chr(41),; $+ $chr(40),;- $+ $chr(40),; $+ $chr(41),;- $+ $chr(41))))  


Could someone with a good knowledge of regex modify this so it detects the following smilies as well as the ones that the code picks up.

shocked ;O :[color:blue]o ;o :| ;| =] =[ =) =( =| =x[/color]
Or any other smiles you can think of, i don't know regex well so any help on this would be fantastic. smile
Posted By: KingTomato Re: Regex question - 29/10/06 07:44 PM
I'll do you one better, and help you learn a little regex. grin

Take your statement you have: /(\:|;)(-)?(P|X|D|\/|\\|\[|\])/ig and break it down:

/(\:|;)(-)?(P|X|D|\/|\\|\[|\])/ig

/ /ig
The two ends and just to specify it is a regex pattern.

(\:|;)
Here we specify the "eyes" of the face. The parenthesis contain all the possible eye combinations seperated by a pipe (| character). The colon is prefixed with a \ because it means something to regex, but we want the literal ':' character.
So to add more eyes, add them between the parenthesis seperated by the pipe (|). In this case, you would like = signs, so this becomes (\:|;|=)

(-)?
This section is for the optional nose (the question mark after the parenthesis means it may or may not be present). Again, if you'd like to add more, add them seperated by a pipe (|) in the parenthesis.

(P|X|D|\/|\\|\[|\])
This is the mouth of the face. Again, all seperated by the pipe (|). What is different here is things such as other parenthesis and brackets are prefixes with a backslash. This is for the same reason as the colon above. Add more mouths seperated by the pipe (|) to this list (you wanted the o, x and pipe, so we would update to look like this: (P|X|D|\/|\\|\[|\]|O|X|\|) -- notice how we escape the pipe cool)

finished product
So now, will the modifications we've done, your end product should look like this: /(\:|;|=)(-)?(P|X|D|\/|\\|\[|\]|O|X|\|)/ig Place that in your $regex() expression and you should be doing great.


To help you out, here are a list of characters you need to prefix with a backslash when adding them to the regular expression: [ ] \ ^ $ . | ? * + ( ) When adding any of these as a possible portion to a face, use a backslash then the character (example: \$ or \.)

Hope that helps. If you have any more questions please ask.
Posted By: Lpfix5 Re: Regex question - 29/10/06 10:12 PM
KingTomato im interested in regex but it still seems complicated

is there good methods of using $regex stuff in something easily understandable that I can use to output stuff and have an explanation on it..

the way i see it /(partofsomething)|(wildcard match or part of the other link of word)/xxxx << xxx being part of the call either a to match all items etc.. but where does the ig come from this is things that are not mentioned in help file and can't learn nothing from it.

then what about the other stuff like $regexsub $regml and so fourth?
Posted By: Mpdreamz Re: Regex question - 29/10/06 10:22 PM
If your interested in a ready built one try my $emoticon snippet. smile
Posted By: b1ink Re: Regex question - 29/10/06 10:28 PM
I think you are using a huge expression for such a thing. also it won't work with ao=] if you tried. You might wanna use this:

/(?<=^| )([:;=][O\|\[\]\050\051x])(?= |$)/igS

Check those also:

PERL Full Regex
$emition's identifier by Mpdreamz <3
Posted By: b1ink Re: Regex question - 29/10/06 10:33 PM
oops.. I've been editing my post until I found you a step behind me :x
© mIRC Discussion Forums