mIRC Home    About    Download    Register    News    Help

Topic Options
#263291 - 04/07/18 07:51 AM Condensing a tokenized string
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2402
I have the string: X(1) X(2) X(4) Y(2) Y(3) Y(7) Z(4) Z(5) Z(6)

and I want to reduce it to: X(1)(2)(4) Y(2)(3)(7) Z(4)(5)(6)

Any suggestions?
_________________________
doiní things a particle can

Top
#263292 - 04/07/18 08:23 AM Re: Condensing a tokenized string [Re: Raccoon]
westor Offline
Hoopy frood

Registered: 27/12/08
Posts: 1491
Loc: Greece
Try use that code:

Code:
alias fitall {
  if (!$1) { return }
  var %text = $1-
  var %t = $numtok(%text,32)
  var %i = 1
  while (%i <= %t) {
    var %v = $gettok(%text,%i,32)
    var %id = $left(%v,1)
    var %value = $right(%v,3)
    if (%id) { set -eu0 %fit_ $+ %id $addtok(%fit_ [ $+ [ %id ] ],%value,32) }
    inc %i
  }

  var %tot = $var(fit_*,0)
  var %z = 1
  while (%z <= %tot) { var %output = %output $right($var(fit_*,%z),-5) $+ $remove($var(fit_*,%z).value,$chr(32)) | inc %z }

  return $iif(%output,$v1,0)
}
_________________________
Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-

Top
#263295 - 04/07/18 02:34 PM Re: Condensing a tokenized string [Re: Raccoon]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3376
Loc: France
I suppose you're not looking for westor's code as you could write something like it but rather an ugly $regsubex, this is the only thing that came to mind immediately

Quote:
//echo -a $regsubex(X(1) X(2) X(4) Y(2) Y(3) Y(7) Z(4) Z(5) Z(6),/([XYZ])(\(\d+\) (?:\1\(\d+\)(?= \1) )*\1\(\d+\))/g,\1 $+ $remove(\2,$chr(32),\1))
if you want it done with a static substitution, I don't think it's possible (or not without assuming too much) but people are surprising with regex...
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#263298 - 04/07/18 11:49 PM Re: Condensing a tokenized string [Re: Wims]
westor Offline
Hoopy frood

Registered: 27/12/08
Posts: 1491
Loc: Greece
Originally Posted By: Wims
I suppose you're not looking for westor's code as you could write something like it but rather an ugly $regsubex, this is the only thing that came to mind immediately

Quote:
//echo -a $regsubex(X(1) X(2) X(4) Y(2) Y(3) Y(7) Z(4) Z(5) Z(6),/([XYZ])(\(\d+\) (?:\1\(\d+\)(?= \1) )*\1\(\d+\))/g,\1 $+ $remove(\2,$chr(32),\1))
if you want it done with a static substitution, I don't think it's possible (or not without assuming too much) but people are surprising with regex...


I FUCKING HATE REGEX !!!!!!!!!!!!!
_________________________
Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-

Top
#263299 - 05/07/18 01:08 AM Re: Condensing a tokenized string [Re: Wims]
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2402
Huh, interesting solutions, both of you. Thanks.
_________________________
doiní things a particle can

Top
#263335 - 10/07/18 04:56 AM Re: Condensing a tokenized string [Re: Raccoon]
jaytea Offline
Fjord artisan

Registered: 23/02/06
Posts: 539
hey Raccoon, this works for single letter function names: https://regex101.com/r/YrBB2y/1
_________________________
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Top
#263344 - 10/07/18 08:21 PM Re: Condensing a tokenized string [Re: jaytea]
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2402
Originally Posted By: jaytea
hey Raccoon, this works for single letter function names: https://regex101.com/r/YrBB2y/1
Code:
//echo -a $regsubex(X(1) X(2) X(4) Y(2) Y(3) Y(7) Z(4) Z(5) Z(6),/(?<=([A-Z]))\(\d+\)\K \1/g,)
> X(1)(2)(4) Y(2)(3)(7) Z(4)(5)(6)

I don't know why I didn't think about look-behinds, since they are indeed single letter and so static in length. Interesting! Thanks!
_________________________
doiní things a particle can

Top