AutID Posted February 23, 2015 Share Posted February 23, 2015 (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 February 23, 2015 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
SadBunny Posted February 23, 2015 Share Posted February 23, 2015 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. Link to comment Share on other sites More sharing options...
mikell Posted February 23, 2015 Share Posted February 23, 2015 (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 February 23, 2015 by mikell Link to comment Share on other sites More sharing options...
AutID Posted February 25, 2015 Author Share Posted February 25, 2015 (edited) I thought the same and it concerns URLs. So in this case they are replaced by and empty string? If yes then why it is like it is and not just an empty string? Edit: like this Local $sString = "Th%20is is %20a t%20est s%20tring" $sString = StringRegExpReplace ( $sString, "%([0-9a-fA-F]{2})", "" ) ConsoleWrite($sString & @LF) Edited February 25, 2015 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
mikell Posted February 26, 2015 Share Posted February 26, 2015 Because the expression above is bad The correct way should be this Local $sString = "Th%20is is %20a t%20est s%20tring" $sString = Execute("'" & StringRegexpReplace($sString, "%([0-9a-fA-F]{2})", "'& Chr(0x$1) &'") & "'") ConsoleWrite($sString & @LF) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now