mIRC Homepage
Posted By: Jigsy $nemove/$nremovecs (or better name) - 27/08/18 12:47 AM
Since changing $remove/$removecs would break compatability afaik, this would most likely need to be a new function.

What I'm proposing is something like $remove, but with the option to remove only a number of relevant characters.

E.g. $nremove(ooohv, 1, o) > oohv
Posted By: maroon Re: $nemove/$nremovecs (or better name) - 27/08/18 03:07 AM
Just to clarify, it seems you want to remove only the first N matches?

Something like this?

//echo -a $regsubex(ooohv,/o/gi,$iif(\n <= 1,$null,o) )

Changing the 1 would determine how many matches would be removed.
Posted By: Wims Re: $nemove/$nremovecs (or better name) - 31/08/18 05:36 PM
You're not mentioning that a while loop on the N parameter + doing a remove in the loop is not an option for you. This is easily scripted, are you looking for mIRC to do the loop for extra efficiency?
Code:
alias -l regesc {
  return \Q $+ $replacecs($3, \E, \E\\E\Q) $+ \E
}

alias nremove {
  var %n = $2
  return $regsubex($1, /( $+ $regesc($3) $+ )/ugi, $iif(\n > %n, \1))
}

alias nremovecs {
  var %n = $2
  return $regsubex($1,/( $+ $regesc($3) $+ )/ug, $iif(\n > %n, \1))
}
Posted By: Wims Re: $nemove/$nremovecs (or better name) - 01/09/18 11:21 AM
I wanted to make this break with one way but couldn't grin
However your $iif is wrong, this code is not working
The idea is to remove the first n occurrences of the 'match'; not keep the first n occurrences, thus there isn't a 'bug' in the iif.

Example:
Code:
Should remove the first 2 occurances
    $nremove(abab-abab, 2, ab) 

resulting in
    -abab


However, there is a typo/bug in $regesc where $3 should be $1:

Code:
alias -l regesc {
  return /(\Q $+ $replacecs($1, \E, \E\\E\Q) $+ \E)/ug $+ $prop
}

alias nremove {
  var %n = $2
  return $regsubex($1, $regesc($3).i, $iif(\n > %n, \1))
}

alias nremovecs {
  var %n = $2
  return $regsubex($1, $regesc($3), $iif(\n > %n, \1))
}
Posted By: Wims Re: $nemove/$nremovecs (or better name) - 01/09/18 11:14 PM
Ah yeah, well at least it's fixed.
© mIRC Discussion Forums