|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
OP
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
|
Hoopy frood
Joined: Dec 2008
Posts: 1,515 |
Try use that 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)
}
|
|
|
|
Joined: Jul 2006
Posts: 4,222
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,222 |
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 //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
|
Hoopy frood
Joined: Dec 2008
Posts: 1,515 |
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 //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 !!!!!!!!!!!!!
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
OP
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
Fjord artisan
|
Fjord artisan
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
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
//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!
|
|
|
|
|