mIRC Homepage
Posted By: HaleyJ regex - 07/04/10 02:22 PM
Hello all,

I am wondering if anyone can help me with a regular expression.

I need a regex to count and return the amount of nonealphabetical characters in a string (not including a space chr(32).

i.e hello world!! will return 2 because of the two exclamation marks at the end

Any replies greatly appreciated.

Thanks

Posted By: qwerty Re: regex - 07/04/10 02:49 PM
You can do it without a regex with something like
Code:
$calc($len($1-) - $count($1-,a,b,c,d,e,f,g,h,i,j,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,$chr(32)))
An equivalent regex solution is
Code:
$regex($1-,/[^ a-z]/gi)
Posted By: HaleyJ Re: regex - 07/04/10 03:34 PM
Hi qwerty,

Really helpful.

thanks
Posted By: Tomao Re: regex - 08/04/10 12:43 AM
You can also use:
Code:
/[[:punct:]]/g
Posted By: FroggieDaFrog Re: regex - 19/04/10 04:05 AM
or:
/[^\s\w]/g
Posted By: Horstl Re: regex - 19/04/10 10:09 PM
Code:
var %t = $chr(15) test!123 $chr(9)
echo -sg ^a-z: $regex(%t,/[^ a-z]/gi) --- \S\W: $regex(%t,/[^\s\w]/g) --- punct: $regex(%t,/[[:punct:]]/g)
by no means equivalents (...the request was quite explicit) smile
Posted By: FroggieDaFrog Re: regex - 19/04/10 10:36 PM
well played. I was thinking chars 32 and after. I didn't consider the tab smile
Posted By: Tomao Re: regex - 20/04/10 03:09 AM
In comparison, qwerty's regex method is like a "negative" check while mine is a "positive."
© mIRC Discussion Forums