How can I selectively escape percent (%) in Python strings?
>>> test = “have it break.” >>> selectiveEscape = “Print percent %% in sentence and not %s” % test >>> print selectiveEscape Print percent % in sentence and not have it break.
>>> test = “have it break.” >>> selectiveEscape = “Print percent %% in sentence and not %s” % test >>> print selectiveEscape Print percent % in sentence and not have it break.
git stash apply n works as of git version 2.11 Original answer, possibly helping to debug issues with the older syntax involving shell escapes: As pointed out previously, the curly braces may require escaping or quoting depending on your OS, shell, etc. See “stash@{1} is ambiguous?” for some detailed hints of what may be going … Read more
Use: grep — -X Documentation Related: What does a bare double dash mean? (thanks to nutty about natty).
Use a duplicated double quote. @”this “”word”” is escaped”; outputs: this “word” is escaped
When your XML contains &, this will result in the text &. When you use that in HTML, that will be rendered as &.
Short ‘n Sweet (Updated 2021) To escape the RegExp itself: function escapeRegExp(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, ‘\\$&’); // $& means the whole matched string } To escape a replacement string: function escapeReplacement(string) { return string.replace(/\$/g, ‘$$$$’); } Example All escaped RegExp characters: escapeRegExp(“All of these should be escaped: \ ^ $ * + ? . ( … Read more
@@ should do it.
There is also the solution from mustache.js var entityMap = { ‘&’: ‘&’, ‘<‘: ‘<’, ‘>’: ‘>’, ‘”‘: ‘"’, “‘”: ‘'’, “https://stackoverflow.com/”: ‘/’, ‘`’: ‘`’, ‘=’: ‘=’ }; function escapeHtml (string) { return String(string).replace(/[&<>”‘`=\/]/g, function (s) { return entityMap[s]; }); }
Use the ensure_ascii=False switch to json.dumps(), then encode the value to UTF-8 manually: >>> json_string = json.dumps(“ברי צקלה”, ensure_ascii=False).encode(‘utf8’) >>> json_string b'”\xd7\x91\xd7\xa8\xd7\x99 \xd7\xa6\xd7\xa7\xd7\x9c\xd7\x94″‘ >>> print(json_string.decode()) “ברי צקלה” If you are writing to a file, just use json.dump() and leave it to the file object to encode: with open(‘filename’, ‘w’, encoding=’utf8′) as json_file: json.dump(“ברי צקלה”, json_file, … Read more
EDIT: This answer was posted a long ago, and the htmlDecode function introduced a XSS vulnerability. It has been modified changing the temporary element from a div to a textarea reducing the XSS chance. But nowadays, I would encourage you to use the DOMParser API as suggested in other anwswer. I use these functions: function … Read more