I have a little AS3 script to convert all special characters in a string to their character codes.
Here is the script:
url = url.replace(new RegExp("%","g"),"%25")
.replace(new RegExp("?","g"),"%3F")
.replace(new RegExp(":","g"),"%3A")
.replace(new RegExp("/","g"),"%2F")
.replace(new RegExp("=","g"),"%3D")
.replace(new RegExp("&","g"),"%26");
Now, I'm not even a beginner with RegExp, but I gave it a try. The little script seems to do the trick quite well, but only the question mark (?) isn't replaced.
Anyone who can tell me why?
If you can also tell me a more short way to code this, feel free to share it, I know this isn't the best practice of RegExp...
greets
.replace(/%/g, "%25"). Note that in this case, the ? would only need one backslash for escaping:/\?/g, because the backslash is not inside a string. There's no other way to replace all occurrences that is shorter, faster or better practice (OK, better practice is debatable). Except if crooksy88's way applies to your case, which I'd say it does.