mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2003
Posts: 157
RuFy Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Nov 2003
Posts: 157
Hi I have this code:
Code:
on ^*:TEXT:*:#:{ echo -a $regex($1-,/[A-Z]/) }


It tell me only if someone write in MAIUSC. But, if I would like to calc how many words are in MAIUSC in the string? shocked

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
$regex($1-,/\b[A-Z]+\b/g)

Note that right now the boundaries for the uppercase alpha words are \b, which will match the position between a non alphanumeric char and an alphanumeric char.

I do this so that in the sentence: WHAT? It would say there's 1 word in upper case, even though technically the string "WHAT?" is not an alpha string, since it contains a question mark. Also in a string like: HEY, you! it will also say there's 1 word in upper case, even though the string "HEY," isn't an alpha string.

Consequence of this is that on the word "SEMI-advanced" it will say there is 1 word in upper case, even though the entire word contains an "-" sign, so isn't technically an alpha char.

If you do only want it to match nothing but alpha chars that can only be surrounded by either a space or the start/end of the string, you could specify:

$regex($1-,/(?<= |^)[A-Z]+(?= |$)/g)


Note that you didn't need a regex for this, a simple loop like the following would have worked just fine.

var %a
while ($0) {
if ($1 isupper) && ($1 isalpha) inc %a
tokenize 32 $2-
}
echo -a %a

Joined: Nov 2003
Posts: 157
RuFy Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Nov 2003
Posts: 157
yes, but this not count how many words are in uppercase. I would like to count how many words are in uppercase in the string. laugh

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
It does. Test it before posting.


Gone.
Joined: Nov 2003
Posts: 157
RuFy Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Nov 2003
Posts: 157
I have tested it and it show only the word without the ? character.

Last edited by RuFy; 23/10/05 06:42 PM.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
//tokenize 32 IT DOES WORK | echo -a $regex($1-,/(?<= |^)[A-Z]+(?= |$)/g)

//tokenize 32 IT DOES WORK | echo -a $regex($1-,/\b[A-Z]+\b/g)

Code:
alias upperwords {
  tokenize 32 $$1
  var %a = 0
  while ($0) { 
    if ($1 isupper) &amp;&amp; ($1 isalpha) inc %a 
    tokenize 32 $2- 
  } 
  return %a 
}


//echo -a $upperwords(IT DOES WORK)


Gone.
Joined: Nov 2003
Posts: 157
RuFy Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Nov 2003
Posts: 157
ok, Thanks for the help laugh

Sorry if I am too stupid grin


Link Copied to Clipboard