This is a custom identifier and command that will return text encoded to suit URLs (e.g. hello%20world)
Usage: $urlencode(text) will return the encoded text, and /urlencode text will echo the encoded text.
Do not enter the whole URL into the text, only the parameter values that need encoding.
alias urlencode {
var %r = $regsubex($$1-,/([!#$%&'()*+,/:;=?@[] ])/g,% $+ $($base($asc(\t),10,16)))
$iif($isid,return,echo -a) %r
}
Oh hmm I definitely entered it as \t, since I copied and pasted my script, but I added the backslash in.
The closing bracket character is escaped, and the only one that needs to be (since $ for example cannot mean the end of a string in a character class.)
Also, not all non-alphanumeric characters should be encoded (even if that is an idea) since only these characters and alpha-num form a valid URI according to internet standards. Even more so, the characters -_.~ should not be encoded.
I don\'t see how it can work, there are quite a few errors with errors with the regex that I can see. $asc(t) would need to be changed to $asc(\t) and all of the []()/ etc. characters in the regex string should be prefixed with a \ so that they are interpreted as characters and not a closing bracket or something. Also there are special regex escape strings which would be much better for capturing all non alphanumeric characters.