Jump to content

Recommended Posts

Posted (edited)

With what does this pattern replace the captured chars?

Local $sString = "Th%is is %a t%est s%tring"
$sString = StringRegExpReplace ( $sString, "%([0-9a-fA-F]+)", Execute ( Chr ( '0x$1' ) ) )
ConsoleWrite($sString & @LF)

In the example it replaces them with empty string. However this doesn't look too logic to me. If it was the case then the third param of of the reg replace would simply be an empty string.

I found this example on internet.

 

Edited by AutID
Posted

Your code will try to change the regex matches by the result value of the Execute command. Chr ( '0x$1' ) amounts to NUL (ascii char 0), thus the Execute command will try to execute the NUL character. That fails, hence the return value of Execute is "" (as noted in the help file).

If you remove the Execute part but leave the Chr ( '0x$1' ) part, the string will get broken off at the first occurance of the regex match, because the match then still gets replaced by NUL, aka a terminator.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Posted (edited)

Sometimes in URLs special characters are replaced by a % followed by their hex value (two hex chars), e.g. %20 for the space

Probably this code is made to convert them back to their ascii representation

Local $sString = "Th%20is is %20a t%20est s%20tring"

$sString = StringRegExpReplace ( $sString, "%([0-9a-fA-F]{2})", Execute(Chr('0x$1')) )
ConsoleWrite($sString & @LF)
Edited by mikell

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...