mIRC Home    About    Download    Register    News    Help

Print Thread
For the regex gurus. #126967 06/08/05 11:12 PM
Joined: Jan 2004
Posts: 509
L
LostShadow Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
var %f = $regsub(%a,/\G(?!.*\b(?:calculus|square|root|-1|negative)\b)(.*?)\bi\b/g,\1I,%a)

This makes "So i need help" to become "So I need help" by capitalizing the letter I.

"The square root of negative 1 is i" does not capitalize i.

However, type /umode +i becomes +I.

I need for it to not include +/- signs before and after it.

2.
How do I make arent aren't? (Not via $replacecs because parents becomes paren'ts).

3.
Code:
alias RemainingUsers {       
  ;  Create the matchtext field for raw 353 and 366 to trigger on  
  ;    set -u600 %353 $me & #$$1 *  
  set -u600 %366 $me #$1 End of /NAMES list.       
  ;  Open a minimized, hidden desktop listwindow to store the nicks
  ; it's entirely possible that this  
  ;  alias might be used on a channel with a large number of nicks (like 2500) which makes storing  
  ;  the nicks in a variable untenable. And since (join) order is quite likely important, a hash table  
  ;  wouldn't be the best idea either. That leaves either a file (slow access) or a hidden @window.  
  window -nhdl @RemainingUsers       
  ;  Now request the join order from /NAMES.  
  .raw names #$1 
}   
;  353 RPL_NAMREPLY
raw 353:%353:{       
  ;  Remove the @'s and +'s from in front of nicks. If your network uses additional symbols in front  
  ;  of nicks, add them to the list of symbols inside the $remove().  
  var %rnicks = $remove($4-, @, +)       
  ;  Check to see if there are already nicks in @RemainingUsers, which would mean that we've found $me  
  ;  somewhere in a previous 353.  
  if $line(@RemainingUsers, 0) {           
    ;  Since $me is already in @RemainingUsers, add all these new nicks to variable.    
  var %nicks = %rnicks    }      
  ;  Or if $me is found in this line, then we can start processing nicks  
  elseif $istok(%rnicks, $me, 32) {          
    ;  Chop off any nicks prior to $me.   
  var %nicks = $gettok(%rnicks, $+($findtok(%rnicks, $me, 1, 32), -), 32)    }      
  ;  Now check to see if we need to process this 353 any more.  
  if (%nicks) {           
    ;  Add each nick to @RemainingUsers   

    var %i = 1   
    while $gettok(%nicks, %i, 32) {      
      aline @RemainingUsers $ifmatch      
      inc %i   
    }  
  }       
  ;  Halt the normal display.  
  halt 
}   
;  Echoing alias for /filter -k used in RPL_ENDOFNAMES to display the nicks.
alias -l f_echo {   
  echo -gtic info2 $gettok(%366, 2, 32) $1  
}  
;  366 RPL_ENDOFNAMES
raw 366:%366:{       
  ;  Get rid of the first line, which will be equal to $me. 
  dline @RemainingUsers 1      
  ;  Display the list however you like. This example uses /filter with an alias to echo.  
  filter -k @RemainingUsers f_echo      
  ;  Clean up the /set variables used and close the data window.  
  unset %353 %366
  window -c @RemainingUsers      
  ;  Halt the normal display. 
  halt
}


This is exactly the same as a /names, and I need it for remaining users only.

3.
Code:
on me:*:JOIN:#: hadd -mu600 MeJoin $+($cid,#) 1 | .raw $+(MODE # b,$crlf,WHO #)
raw 352:*: if ($hget(MeJoin, $+($cid,$2))) halt
raw 315:*: if ($hget(MeJoin, $+($cid,$2))) { hdel MeJoin $+($cid,$2) | halt }
raw 367:*: if ($hget(MeJoin, $+($cid,$2))) halt
raw 368:*: if ($hget(MeJoin, $+($cid,$2))) halt


Sorry but I still see /mode # b in my status, the purpose is to hide it.

4.
Also, how do I return the first letter of every word in a $1- string. I'm trying to bold every first letter of every word, but I can only bold the first letter of the first and last word, not the words in between.

5.
/totalchannel {
var %n = $scon(0), %totalchannel = 0
while (%n) {
scon %n
inc %totalchannel $chan(0)
dec %n
}
return %totalchannel
}

That returns total channel windows. So it counts channel windows that I may not be in, like disconnects and kicks. How do I return "joined" channels?

Basically, I need to return "$chan(0).status" for 'joined' only.

Thanks.

Re: For the regex gurus. #126968 07/08/05 02:49 AM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
1) Use a negative lookback:

Code:
$regsub(%a,/\G(?!.*\b(?:calculus|square|root|-1|negative)\b)(.*?)\b(?<!\+)i\b/g,\1I,%a)


2) Use $regsub:

Code:
var %a, %b = $regsub(<text>,/\barent\b/g,aren't,%a) | do whatever with %a


4) Use a while loop or $regsub:

Code:
var %i = 1, %bold
while ($eval($ $+ %i,2) != $null) {
  %bold = %bold $+(,$left($v1,1),,$mid($v1,2))
  inc %i
}
echo -a %bold


Code:
//var %a, %b = $regsub($1-,/(?<=^| )(.)/g,\1,%a) | echo -a %a


5) This will only count the channels you're in on connected servers:

Code:
alias totalchannels {
  var %channels
  scid -at1 inc % $+ channels $!countchannels
  return %channels
}
alias countchannels { return $chan(0) }

Last edited by tidy_trax; 07/08/05 02:55 AM.
Re: For the regex gurus. #126969 07/08/05 09:12 AM
Joined: Apr 2003
Posts: 701
K
Kelder Offline
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
4) I'd use this to only bold letters of words:
//var %a, %b = $regsub($1-,/(?<=^| )([a-z])(?=[a-z ])/gi,\1,%a) | echo -a %a

5) Why the extra alias confused
alias totalchannels {
var %channels
scid -at1 inc % $+ channels $!chan(0)
return %channels
}

Re: For the regex gurus. #126970 07/08/05 09:26 AM
Joined: Aug 2003
Posts: 314
S
Sigh Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
To return joined channels use the suggestions mentioned above, but change $chan(0) to $comchan($me,0), for example:

Code:
alias totalchannels var %c = 0 | scon -at1 inc $(%c $comchan($me,0),) | return %c

Re: For the regex gurus. #126971 07/08/05 03:38 PM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Quote:
5) Why the extra alias confused


It was nearly 5am.. that's my only excuse :tongue:


New username: hixxy
Re: For the regex gurus. #126972 07/08/05 09:23 PM
Joined: Jan 2004
Posts: 509
L
LostShadow Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
Okay thanks for the help and input guys.

Several others.

How do you return total channels per one network? $chan(0) will return channels you are not in. I removed the /scon part but then it returned 1.

var %b = $regsub(%a,/\s?([?!\54])\1*/g,\1,%a)

This makes ! and???? to make! and?

So hi ! becomes hi! and what???? becomes what?

But, $nick != that makes $nick!= that

So I don't want it to concatenate if there's an equal sign after !
So, whatever follows a ? or a ! will make it concatenate I need an exception to that.

%a being $1-

$regsub(%a,/\b(?<!#)u\b/g,you,%a)
$regsub(%a,/\b(?<!#)y\b/g,why,%a)

That makes u become you and usa become usa, but U.S.A. becomes You.S.A.

Then, y.o.u.r. becomes why.o.you.r.

I need exceptions to periods.

Thanks.

Re: For the regex gurus. #126973 07/08/05 09:50 PM
Joined: Apr 2003
Posts: 701
K
Kelder Offline
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
var %b = $regsub(%a,/\s?([?!\54])\1*+(?!=)/g,\1,%a)

This will not change !!!!!= ,,,,,,= or ??=. The atomic grouping (the *+ part) is necessary here...


$regsub(%a,/\b(?<![#.])u\b(?!\.(?:\w|$))/g,you,%a)
$regsub(%a,/\b(?<![#.])y\b(?!\.(?:\w|$))/g,why,%a)

If you follow the rule to put a space between the end . of a sentence and the next sentence, this should work. I also check for a . before the y or u to prevent replacements when the letter is last in an abbreviation.

Have fun with this, and don't forget to put pcre.txt under your pillow at night smile

Re: For the regex gurus. #126974 08/08/05 12:05 AM
Joined: Aug 2003
Posts: 314
S
Sigh Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
Quote:
How do you return total channels per one network? $chan(0) will return channels you are not in.


Are you asking the same thing as you did in q.5 of your first post? If so, look closely, I answered

Re: For the regex gurus. #126975 09/08/05 05:16 AM
Joined: Jan 2004
Posts: 509
L
LostShadow Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
Quote:

Are you asking the same thing as you did in q.5 of your first post? If so, look closely, I answered


Different. First question was regarding all channels in all networks, this one is all channels in on network only.