mIRC Home    About    Download    Register    News    Help

Print Thread
#135226 09/11/05 12:24 PM
Joined: Nov 2003
Posts: 157
RuFy Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Nov 2003
Posts: 157
Hi, I have not practice with regex, and I need a code that return how many upper case letters are in a string.
And another code in regex that return how many char are in the string.
Someone can help me?

laugh

#135227 09/11/05 01:29 PM
A
Anonymous
Unregistered
Anonymous
Unregistered
A
regular expressions are very easy, although they look like a monster
smile

i recommend this small application "reg-ex coach" : http://weitz.de/files/regex-coach.exe that checks your regular expression and tells you what the pattern would be

and also check tutorials about regular expressions on google. they are just so easy to learn you wouldn't belive it. all you need to know is contained in 2-3 paragraphs at most.

good luck! smile

#135228 09/11/05 02:03 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
And, just for your last part... you don't need regex.

/help $len

//echo -a $len(This is a test)
14


Invision Support
#Invision on irc.irchighway.net
#135229 09/11/05 02:05 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Number of upper case chars in a string: $regex($1-,/[A-Z]/g)


Gone.
#135230 09/11/05 05:10 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Anyway, it's obvious where this is going, you want to detect the percentage of caps in a sentence probably.

/*

Usage: $caps(string)[.property]

If no property is specified, it returns the number of caps in the string, else it returns the percentage of caps.

Available properties:

alpha: compares to all alpha characters
nonspace: compares to all non-space chars (tab is not a space)
all: compares to all chars

Examples:

//echo -a $caps(ab CD12*)
//echo -a $caps(ab CD12*).alpha
//echo -a $caps(ab CD12*).nonspace
//echo -a $caps(ab CD12*).all

*/

Code:
alias caps {
  var %caps = $regex($$1,/[A-Z]/g), %type = alpha nonspace all
  if (!$prop) return %caps
  if (!$istok(%type,$prop,32)) return Bad property
  return $calc(100*%caps /$regex($1,/ $gettok([a-z];[^ ];.,$findtok(%type,$prop,1,32),59) /gisx)))
}


Gone.

Link Copied to Clipboard