mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
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?


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
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? -> https://irc.chathub.org <-
Joined: Jul 2006
Posts: 4,164
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,164
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...


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
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? -> https://irc.chathub.org <-
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Huh, interesting solutions, both of you. Thanks.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
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!


Well. At least I won lunch.
Good philosophy, see good in bad, I like!

Link Copied to Clipboard