mIRC Home    About    Download    Register    News    Help

Print Thread
regex smaller #179896 30/06/07 12:12 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Code:
alias _Tokenize { 
  var %x = 1 
  while (%x <= $numtok($1-,32)) { 
    var %y = %y $+(04[01,%x,04,$chr(44),01,$gettok($1-,%x,32),04]) 
    inc %x 
  } 
  echo -s %y 
} 


Is there a way i can make that smaller perhaps using a regsubex guys?

Re: regex smaller [Re: pouncer] #179899 30/06/07 12:55 AM
Joined: Mar 2003
Posts: 612
B
billythekid Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
$numtok($1-,32) can be replaced with $0


billythekid
Re: regex smaller [Re: pouncer] #179903 30/06/07 03:14 AM
Joined: Feb 2005
Posts: 342
R
Rand Offline
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Sure.

Code:
alias _tokenize { echo -s $regsubex($1-,/(\S+)/g,$+(04[01,\n,04,$chr(44),01,\t,04])) }

Re: regex smaller [Re: pouncer] #179927 30/06/07 12:41 PM
Joined: May 2007
Posts: 89
T
TropNul Offline
Babel fish
Offline
Babel fish
T
Joined: May 2007
Posts: 89
If I correctly understood the objective, here's what can replace it.

Code:

Alias _Tokenize { Echo -s $regsubex($1-,/(\S+)/g,$+(04[01,\n,04,$chr(44),01,\1,04])) }




Explanations:

Pattern: /(\S+)/g means " unless a space is matched, continue to match " . So this method will locate one after the other, each word of the string.



tropnul
Re: regex smaller [Re: pouncer] #179937 30/06/07 03:18 PM
Joined: Oct 2006
Posts: 166
B
b1ink Offline
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
Here's another method:
Code:
[code]alias _tokenize tokenize 32 $1 | scon -r var $(%b = %b ,) $!+(4[,$calc( $!numtok(%b,32) +1),4,$chr(44),, $* ,4]) | return %bn %b %
[/code]


Kind Regards, blink
Re: regex smaller [Re: pouncer] #179938 30/06/07 03:36 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
Code:
alias _Tokenize { echo -s $regsubex($1-,/([^ ]+)/g,$+(04[01\n04,$chr(44),01\t04])) }

Re: regex smaller [Re: b1ink] #179939 30/06/07 03:53 PM
Joined: Apr 2004
Posts: 841
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 841
Quote:
scon -r .. $* ..

Never use that method unless you know exactly what the input will be. It will double-evaluate the contents of $1-, so if there's external input on there, you open up a huge security hole.

Try "//echo -ag $_tokenize($!pi)" if you don't believe me.


Saturn, QuakeNet staff
Re: regex smaller [Re: Sat] #179941 30/06/07 04:47 PM
Joined: Oct 2006
Posts: 166
B
b1ink Offline
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
Thanks. it depends on what you are trying to pass with the identifier. I just posted that for fun tbh


Kind Regards, blink
Re: regex smaller [Re: hixxy] #179942 30/06/07 04:48 PM
Joined: Oct 2006
Posts: 166
B
b1ink Offline
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
why not \S :P


Kind Regards, blink
Re: regex smaller [Re: b1ink] #179943 30/06/07 04:53 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
\S matches any char except 'whitespace'. This term however includes not only normal spaces (char 32) but also tabs, cr, lf etc. Those are not displayed as spaces in mirc windows.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: regex smaller [Re: b1ink] #179944 30/06/07 05:28 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
The other change I made is that you do not need to use $+ to separate \t and \n from other text in the replacement parameter of $regsubex.

Re: regex smaller [Re: hixxy] #180004 02/07/07 05:36 AM
Joined: Oct 2006
Posts: 166
B
b1ink Offline
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
mm nice


Kind Regards, blink