mIRC Homepage

regex smaller

Posted By: pouncer

regex smaller - 30/06/07 12:12 AM

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?
Posted By: billythekid

Re: regex smaller - 30/06/07 12:55 AM

$numtok($1-,32) can be replaced with $0
Posted By: Rand

Re: regex smaller - 30/06/07 03:14 AM

Sure.

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

Re: regex smaller - 30/06/07 12:41 PM

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.

Posted By: b1ink

Re: regex smaller - 30/06/07 03:18 PM

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]
Posted By: hixxy

Re: regex smaller - 30/06/07 03:36 PM

Code:
alias _Tokenize { echo -s $regsubex($1-,/([^ ]+)/g,$+(04[01\n04,$chr(44),01\t04])) }
Posted By: Sat

Re: regex smaller - 30/06/07 03:53 PM

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.
Posted By: b1ink

Re: regex smaller - 30/06/07 04:47 PM

Thanks. it depends on what you are trying to pass with the identifier. I just posted that for fun tbh
Posted By: b1ink

Re: regex smaller - 30/06/07 04:48 PM

why not \S :P
Posted By: qwerty

Re: regex smaller - 30/06/07 04:53 PM

\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.
Posted By: hixxy

Re: regex smaller - 30/06/07 05:28 PM

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.
Posted By: b1ink

Re: regex smaller - 02/07/07 05:36 AM

mm nice
© 2020 mIRC Discussion Forums