Before anything else, you should first state what you're trying to do.
In addition, I get the impression that you haven't learned regex enough to be able to grasp any explanation at this point.
Your first code seems to want to remove a certain char specified by it's numeric representation, and its preceeding char. $backsp(this is a test,$asc(i)) returns tss a test. You don't need a while loop for that, you can use the /g modifier that will make the regex engine repeat the pattern on the string until all matches have been made.
/*
Usage: $backsp(string,character)
Example: //echo -a $backsp(this is a test,s)
*/
alias backsp {
var %a, %b = $regsub($1,/(?:^|.)\ $+ $base($asc($2),10,8) /gx,,%a)
return %a
}
Note that I used the x modifier, which will ignore unescaped whitespace in the expression, and I made the first pair of brackets uncapturing, since you're not referencing them anywhere. Also note that a lot of characters have a meaning in a regex. I've changed the regsub so that you can input an actual character instead of it's ascii numeric representation. However, with that there is a danger accompanied. Since we have that \ in the expression, for example if we would have used the character "S" as input, it would turn into \S which means "match a non whitespace character". To avoid this I use the octal representation of any character you input, making sure there will be no conflicts with built-in regex constructs. In theory there could be a conflict with backreferences, but since we're not capturing anything, this will form no problem.
Your second code seems to want to underline any character that is neither a "g" or a "p". It does however only do one substitution because the regex engine by nature is lazy, unless you force it not to be. If you want to make the regex engine keep doing substitutions, specify the /g modifier, like was done in the backsp code.
Note that some day you are going to run into trouble because you're not using the regex delimiters / / to enclose your regex patterns. This is especially true if you use regex in events when specifying the $ event prefix, I've had patterns not work due to lacking / /, even in the case where the expression didn't start with an "m". If you know regex, you'll know what I mean with that.
The modifiers come after the second regex delimiter /, or you can specify them by putting them inside brackets like this (?<modifiers>)
I think you need to do some more reading and practicing, here's a good
tutorialHere's also a link to the main reference for anything regarding PCRE, which is the regex library that mIRC also uses:
pcre.txt, although I don't recommend it at first as it's somewhat hard to read through. I'd go with the tutorial first.