mIRC Homepage
This always used to work, but it doesn't appear to any more. Perhaps mIRC 7.x broke it.

The alias is:
Code:
alias urlencode return $regsubex($1,/([< >%{}|\^~[]`])/g,% $+ $base($asc(\t),10,16))


If you feed the alias "hello 123" it should return "hello%20123". It should also encode the other characters in the expression.

Can anybody see what's wrong?!

Thanks in advance.
The problem is the presence of the ] character within the character set creating bad regular expression syntax. You can either escape it with a backslash or put it as the first character within the character set (ie. /([[color:red]]< >%{}|\^~[`])/g[/color])

I'm not sure if that would've worked with any version of mIRC (more specifically the version of PCRE used by mIRC), generally having all those characters with possible syntactic meaning in the expression will be a bit of a minefield. I would either escape them all or better yet use a more comprehensive expression that will URL-encode any non-alphanumeric character without having to specify them all in the expression.

Personally I use one of the following:
Code:
; Escapes all non-alphanumeric characters (except underscore which is fine)
alias urlencode return $regsubex($1,/([^\w\d])/g,% $+ $base($asc(\t),10,16))

; or

; As above but converts space to a +
alias urlencode return $replace($regsubex($1,/([^\w\d\x20])/g,% $+ $base($asc(\t),10,16)), $chr(32), +)
Posted By: hixxy Re: What's wrong with this regular expression? - 30/05/11 11:44 PM
Just to let you know, \w actually incorporates \d. This is probably so that it matches things like "2nd", "3rd" etc.

\w is equivalent to [a-zA-Z0-9_]

This is my urlencode alias:

Code:
alias urlencode { return $regsubex($1,/(\W)/g,% $+ $base($asc(\t),10,16,2)) }
Great - thanks very much guys.
© mIRC Discussion Forums