mIRC Home    About    Download    Register    News    Help

Print Thread
#220199 07/04/10 02:22 PM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
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



Newbie
HaleyJ #220200 07/04/10 02:49 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
qwerty #220204 07/04/10 03:34 PM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
Hi qwerty,

Really helpful.

thanks


Newbie
HaleyJ #220235 08/04/10 12:43 AM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
You can also use:
Code:
/[[:punct:]]/g

HaleyJ #220587 19/04/10 04:05 AM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
or:
/[^\s\w]/g


I am SReject
My Stuff
FroggieDaFrog #220604 19/04/10 10:09 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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

Horstl #220607 19/04/10 10:36 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
well played. I was thinking chars 32 and after. I didn't consider the tab smile


I am SReject
My Stuff
FroggieDaFrog #220615 20/04/10 03:09 AM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
In comparison, qwerty's regex method is like a "negative" check while mine is a "positive."


Link Copied to Clipboard