In all of them
The use of $$n in an identifier alias should be frowned apon, and $$n which does not exist well cause an HALT of the entire calling script, thats hardly the expected action of doing a $wildtok or a $findtok.
As an example you might be sent a line like !trigger \bolt \lock \latch \bolt \lid from this you wish to do $findwildtok($2-, \*, 1 , 1 , 32) or exactly $findwildtok(\bolt \lock \latch \bolt \lid, \*, 1 , 1 , 32), for that everything is ok but what if you recieved a line with just !trigger $2- is $null but the two funtions should be able to cope with this each returning a $null result.
I also didnt like the behavour if $3 used as the wildcard Nth matching counter was zero (total matches), it could cause abnormal/unexpected results. the wildmatch would return a value of total wildcard matches, that value would then be used as the actual matched text of the wildcard
As an example take $findwildtok(1 aa 2 ab 3 ac 4 ad 5 , a* , 0 , 1 , 32) a* matches 4 times and then the 1st occrance of 4 is the 7th token which doesnt match a* at all but is the result.
In rep and rem
If the wildtok fails to locate a matching token, the rep or rem tok recieves no token to match, and should return an unmodified string (IMO) however the actual action of rep and rem tok in these cases is to return no string at all.
examples $remwildtok(1 aa 2 ab 3 ac 4 ad 5 , ?e , 1 , 1 , 32) & $repwildtok(1 aa 2 ab 3 ac 4 ad 5 , ?e , 1 , XX , 1 , 32)
While this deviates from the normal behavour of token identifiers slightly, i feel it is an improvement, that should this occur the original string is returned
So heres what i offer...
alias findwildtok { return $iif(!$int($3),$wildtok($1,$2,$3,$5),$findtok($1,$wildtok($1,$2,$3,$5),$4,$5)) | :error | reseterror }
alias repwildtok { return $iif(!$int($3),$1,$iif($wildtok($1,$2,$3,$6) == $null,$1,$reptok($1,$v1,$4,$5,$6))) | :error | reseterror | return $1 }
alias remwildtok { return $iif(!$int($3),$1,$iif($wildtok($1,$2,$3,$5) == $null,$1,$remtok($1,$v1,$4,$5))) | :error | reseterror | return $1 }
The outter $iif checks if $3 is 0 and returns in the first instance the number of tokens wild matched, and in the other 2 the original string
In rep and rem should $3 have not been 0 the second $iif takes place which checks if the wild tok returns $null (but not zero), if so it returns the original string
else the calculation takes place.
Lastley i added some error trapping, I dont think they can error but why take the chance, returning $null on find, and the original text on the other two.