The below snippet with tell you the percentage of capital letters , lowercase letters or both. It will only take into account letters in the string being checked.
Update: Removed variables and placed $regex inside $calc itself. Also made the % optional for each version. ( June 9th '08 )
Update: Redid the code a bit to make it shorter and easier to use. ( August 27th '08 )
;http://www.hawkee.com/snippet/3325/ ( based off of )
;--- Usage ----------------
;--- $iscaps(string).u <-- %caps
;--- $iscaps(string).up <-- %caps /w % after number
;--- $iscaps(string).l <-- %lowercase
;--- $iscaps(string).lp <-- %lowercase /w % after number
;--- $iscaps(string) <-- %caps , %lowercase
;--- $iscaps(string).p <-- %caps , %lowercase /w % after numbers
;--------------------------
;http://www.hawkee.com/snippet/3325/ ( based off of )
;--- Usage ----------------
;--- $iscaps(string).u <-- %caps
;--- $iscaps(string).up <-- %caps /w % after number
;--- $iscaps(string).l <-- %lowercase
;--- $iscaps(string).lp <-- %lowercase /w % after number
;--- $iscaps(string) <-- %caps , %lowercase
;--- $iscaps(string).p <-- %caps , %lowercase /w % after numbers
;--------------------------
alias iscaps {
if ($isid) {
if (u isin $prop) {
return $+($round($calc( $regex($1,/[A-Z]/g) / $regex($1,/[A-Z]/gi) * 100),2),$iif(p isin $prop,$chr(37)))
}
if (l isin $prop) {
return $+($round($calc( $regex($1,/[a-z]/g) / $regex($1,/[A-Z]/g) * 100),2),$iif(p isin $prop,$chr(37)))
}
if (!$prop || $prop == p) {
return $+($round($calc( $regex($1,/[A-Z]/g) / $regex($1,/[A-Z]/gi) * 100),2),$iif(p isin $prop,$chr(37))) , $&
$+($round($calc( $regex($1,/[a-z]/g) / $regex($1,/[A-Z]/gi) * 100),2),$iif(p isin $prop,$chr(37)))
}
}
}
http://www.hawkee.com/phpBB2/viewtopic.php?t=9764
Try that, it\'s how I learnt.
Eh, it works at the very least, but the coding is not really stunning. Perhaps only declare variables once? Also, there are some letters you are missing support for (A-ZŠŒŽÀ-ÖØ-ÞŸ).
Now besides the coding: I find that adding a % to the end of the returned value is completely useless. What if I wanted to use this for a caps kicker? I\'d have to use $remove or $left or so.
But in any case, this is a nice example of regex and how it can be used. Perhaps add a .count property to return the total matches (basically without a percentage)? Good luck.