mIRC Home    About    Download    Register    News    Help

Print Thread
Regex question #163426 29/10/06 07:12 PM
Joined: Feb 2006
Posts: 164
V
vexed Offline OP
Vogon poet
OP Offline
Vogon poet
V
Joined: Feb 2006
Posts: 164
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

Re: Regex question #163427 29/10/06 07:44 PM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
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.


-KingTomato
Re: Regex question #163428 29/10/06 10:12 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
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?


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Regex question #163429 29/10/06 10:22 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
If your interested in a ready built one try my $emoticon snippet. smile


$maybe
Re: Regex question #163430 29/10/06 10:28 PM
Joined: Oct 2006
Posts: 166
B
b1ink Offline
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
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

Last edited by b1ink; 29/10/06 10:28 PM.

Kind Regards, blink
Re: Regex question #163431 29/10/06 10:33 PM
Joined: Oct 2006
Posts: 166
B
b1ink Offline
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
oops.. I've been editing my post until I found you a step behind me :x


Kind Regards, blink