mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2006
Posts: 2
A
Bowl of petunias
OP Offline
Bowl of petunias
A
Joined: Feb 2006
Posts: 2
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.

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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), +)


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
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)) }

Joined: Feb 2006
Posts: 2
A
Bowl of petunias
OP Offline
Bowl of petunias
A
Joined: Feb 2006
Posts: 2
Great - thanks very much guys.


Link Copied to Clipboard