Questions tagged [escaping]
Escaping is the process of applying an alternate meaning to a character or set of characters.
escaping
9,026
questions
2441
votes
12
answers
1.1m
views
How to replace a character by a newline in Vim
I'm trying to replace each , in the current file by a new line:
:%s/,/\n/g
But it inserts what looks like a ^@ instead of an actual newline. The file is not in DOS mode or anything.
What should I ...
1148
votes
10
answers
1.3m
views
What characters do I need to escape in XML documents?
What characters must be escaped in XML documents, or where could I find such a list?
923
votes
13
answers
749k
views
Saving UTF-8 texts with json.dumps as UTF-8, not as a \u escape sequence
Sample code (in a REPL):
import json
json_string = json.dumps("ברי צקלה")
print(json_string)
Output:
"\u05d1\u05e8\u05d9 \u05e6\u05e7\u05dc\u05d4"
The problem: it's not human ...
836
votes
17
answers
702k
views
Insert HTML into view from AngularJS controller
Is it possible to create an HTML fragment in an AngularJS controller and have this HTML shown in the view?
This comes from a requirement to turn an inconsistent JSON blob into a nested list of id: ...
773
votes
26
answers
661k
views
HTML-encoding lost when attribute read from input field
I’m using JavaScript to pull a value out from a hidden field and display it in a textbox. The value in the hidden field is encoded.
For example,
<input id='hiddenId' type='hidden' value='chalk &...
692
votes
1
answer
444k
views
Escape string for use in Javascript regex [duplicate]
Possible Duplicate:
Is there a RegExp.escape function in Javascript?
I am trying to build a javascript regex based on user input:
function FindString(input) {
var reg = new RegExp('' + input ...
682
votes
16
answers
311k
views
Escape @ character in razor view engine
I am creating a sample ASP.NET MVC 3 site using Razor as view engine. The razor syntax starts with @ character e.g. @RenderBody(). If I write @test on my cshtml page it gives me parse error
CS0103: ...
658
votes
27
answers
775k
views
Escaping HTML strings with jQuery
Does anyone know of an easy way to escape HTML from strings in jQuery? I need to be able to pass an arbitrary string and have it properly escaped for display in an HTML page (preventing JavaScript/...
611
votes
10
answers
860k
views
How do I escape ampersands in XML so they are rendered as entities in HTML?
I have some XML text that I wish to render in an HTML page. This text contains an ampersand, which I want to render in its entity representation: &.
How do I escape this ampersand in the ...
585
votes
7
answers
435k
views
Can I escape a double quote in a verbatim string literal?
In a verbatim string literal (@"foo") in C#, backslashes aren't treated as escapes, so doing \" to get a double quote doesn't work. Is there any way to get a double quote in a verbatim string literal?
...
562
votes
10
answers
485k
views
How to Git stash pop specific stash in 1.8.3?
I just upgraded Git. I'm on Git version 1.8.3.
This morning I tried to unstash a change 1 deep in the stack.
I ran git stash pop stash@{1} and got this error.
fatal: ambiguous argument 'stash@1': ...
516
votes
12
answers
188k
views
How can I grep for a string that begins with a dash/hyphen?
I want to grep for the string that starts with a dash/hyphen, like -X, in a file, but it's confusing this as a command line argument.
I've tried:
grep "-X"
grep \-X
grep '-X'
447
votes
6
answers
484k
views
How can I selectively escape percent (%) in Python strings?
I have the following code
test = "have it break."
selectiveEscape = "Print percent % in sentence and not %s" % test
print(selectiveEscape)
I would like to get the output:
Print percent % in ...
435
votes
18
answers
406k
views
Escape a string for a sed replace pattern
In my bash script I have an external (received from user) string, which I should use in sed pattern.
REPLACE="<funny characters here>"
sed "s/KEYWORD/$REPLACE/g"
How can I ...
410
votes
9
answers
449k
views
How to escape indicator characters (colon and hyphen) in YAML
In a config file, I have a key to which I wish to assign a URL. The problem is that YAML interprets : and - characters as either creating mappings or lists, so it has a problem with the line
url: http:...
404
votes
14
answers
346k
views
Pass a PHP variable to a JavaScript variable
What is the easiest way to encode a PHP string for output to a JavaScript variable?
I have a PHP string which includes quotes and newlines. I need the contents of this string to be put into a ...
378
votes
11
answers
395k
views
How to use a variable inside a regular expression
I'd like to use a variable inside a regex, how can I do this in Python?
TEXTO = sys.argv[1]
if re.search(r"\b(?=\w)TEXTO\b(?!\w)", subject, re.IGNORECASE):
# Successful match
else:
#...
361
votes
8
answers
243k
views
How to escape text for regular expression in Java?
Does Java have a built-in way to escape arbitrary text so that it can be included in a regular expression? For example, if my users enter "$5", I'd like to match that exactly rather than a &...
353
votes
5
answers
402k
views
How to execute a bash command stored as a string with quotes and asterisk [duplicate]
I try to execute the following command :
mysql AMORE -u username -ppassword -h localhost -e "SELECT host FROM amoreconfig"
I store it in a string :
cmd="mysql AMORE -u username -ppassword -h ...
347
votes
6
answers
324k
views
How do I properly escape quotes inside HTML attributes?
I have a drop down on a web page which is breaking when the value string contains a quote.
The value is "asd, but in the DOM it always appears as an empty string.
I have tried every way I know to ...
320
votes
6
answers
312k
views
How to properly escape a double quote in CSV?
I have a line like this in my CSV:
"Samsung U600 24"","10000003409","1","10000003427"
Quote next to 24 is used to express inches, while the quote just next to that quote closes the field. I'm ...
311
votes
10
answers
226k
views
How can I escape square brackets in a LIKE clause?
I am trying to filter items with a stored procedure using like. The column is a varchar(15). The items I am trying to filter have square brackets in the name.
For example: WC[R]S123456.
If I do a ...
307
votes
7
answers
599k
views
Which characters need to be escaped when using Bash?
Is there any comprehensive list of characters that need to be escaped in Bash? Can it be checked just with sed?
In particular, I was checking whether % needs to be escaped or not. I tried
echo "h%h" ...
306
votes
34
answers
362k
views
Unescape HTML entities in JavaScript?
I have some JavaScript code that communicates with an XML-RPC backend.
The XML-RPC returns strings of the form:
<img src='myimage.jpg'>
However, when I use JavaScript to insert the strings into ...
304
votes
12
answers
456k
views
What is the recommended way to escape HTML symbols in plain Java?
Is there a recommended way to escape <, >, " and & characters when outputting HTML in plain Java code? (Other than manually doing the following, that is).
String source = "The less than ...
266
votes
11
answers
922k
views
How do I use spaces in the Command Prompt?
How can I use spaces in the Windows Command Line?
cmd /C C:\Program Files (x86)\WinRar\Rar.exe a D:\Hello 2\File.rar D:\Hello 2\*.*
258
votes
6
answers
326k
views
Convert XmlDocument to String
Here is how I'm currently converting XMLDocument to String
StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
xmlDoc.WriteTo(xmlTextWriter)...
256
votes
14
answers
597k
views
Escape quotes in JavaScript
I'm outputting values from a database (it isn't really open to public entry, but it is open to entry by a user at the company -- meaning, I'm not worried about XSS).
I'm trying to output a tag like ...
246
votes
7
answers
285k
views
How to escape double quotes in a title attribute
I am trying to use a string that contains double quotes in the title attribute of an anchor. So far I tried these:
<a href=".." title="Some \"text\"">Some text</a>
<!-- The title looks ...
243
votes
1
answer
111k
views
PHP sprintf escaping %
I want the following output:-
About to deduct 50% of € 27.59 from your Top-Up account.
when I do something like this:-
$variablesArray[0] = '€';
$variablesArray[1] = 27.59;
$stringWithVariables = ...
241
votes
8
answers
199k
views
Escape single quote character for use in an SQLite query
I wrote the database schema (only one table so far), and the INSERT statements for that table in one file. Then I created the database as follows:
$ sqlite3 newdatabase.db
SQLite version 3.4.0
Enter &...
238
votes
9
answers
399k
views
How can I escape a single quote?
How can I escape a ' (single quote) in HTML?
This is where I'm trying to use it:
<input type='text' id='abc' value='hel'lo'>
The result for the above code is "hel" populated in the ...
238
votes
1
answer
195k
views
How to escape hash character in URL
How can I escape the # hash sign (sometimes known as number sign or pound sign) sent in the query string of a URL?
233
votes
16
answers
251k
views
Can I convert a C# string value to an escaped string literal?
In C#, can I convert a string value to a string literal, the way I would see it in code? I would like to replace tabs, newlines, etc. with their escape sequences.
If this code:
Console.WriteLine(...
233
votes
8
answers
267k
views
Escaping single quote in PHP when inserting into MySQL [duplicate]
I have a perplexing issue that I can't seem to comprehend...
I have two SQL statements:
The first enters information from a form into the database.
The second takes data from the database entered ...
219
votes
17
answers
522k
views
How to escape a JSON string containing newline characters using JavaScript?
I have to form a JSON string in which a value is having new line character. This has to be escaped and then posted using AJAX call. Can any one suggest a way to escape the string with JavaScript. I am ...
217
votes
5
answers
656k
views
How do I escape a single quote ( ' ) in JavaScript? [duplicate]
UPDATE:
I want to give an updated answer to this question. First, let me state if you're attempting to accomplish what I have below, I recommend that you manage events by adding event listeners ...
215
votes
5
answers
50k
views
How can you escape the @ character in javadoc?
How can I escape the @ symbol in javadoc? I am trying to use it inside a {@code} tag, which is inside <pre> tags.
I already tried the html escape @ sequence, but that didn't work.
214
votes
18
answers
253k
views
What is the HtmlSpecialChars equivalent in JavaScript?
Apparently, this is harder to find than I thought it would be. And it even is so simple...
Is there a function equivalent to PHP's htmlspecialchars built into JavaScript? I know it's fairly easy to ...
206
votes
5
answers
357k
views
Why shouldn't `'` be used to escape single quotes?
As stated in, When did single quotes in HTML become so popular? and Jquery embedded quote in attribute, the Wikipedia entry on HTML says the following:
The single-quote character ('), when used to ...
195
votes
3
answers
100k
views
how to parse a JSON String with jq (or other alternatives)?
I'm trying to get jq to parse a JSON structure like:
{
"a" : 1,
"b" : 2,
"c" : "{\"id\":\"9ee ...\",\"parent\":\"abc...\"}\n"
}
That is, an element in the JSON is a string with escaped json.
...
195
votes
11
answers
368k
views
How to escape apostrophe (a single quote) in MySql?
The MySQL documentation says that it should be \'. However, both scite and mysql shows that '' works. I saw that and it works. What should I do?
194
votes
11
answers
56k
views
How to escape @ characters in Subversion managed file names?
For many Subversion operations, appending the '@' symbol to the end of a file or URL argument allows you to target a specific revision of that file. For example, "svn info test.txt@1234" will give ...
187
votes
11
answers
485k
views
Escaping ampersand character in SQL string [duplicate]
I am trying to query a certain row by name in my sql database and it has an ampersand. I tried to set an escape character and then escape the ampersand, but for some reason this isn't working and I'm ...
183
votes
8
answers
151k
views
How do I escape ampersands in batch files?
How do I escape ampersands in a batch file (or from the
Windows command line) in order to use the start command to
open web pages with ampersands in the URL?
Double quotes will not work with start; ...
182
votes
20
answers
525k
views
How should I escape strings in JSON?
When creating JSON data manually, how should I escape string fields? Should I use something like Apache Commons Lang's StringEscapeUtilities.escapeHtml, StringEscapeUtilities.escapeXml, or should I ...
177
votes
8
answers
154k
views
Process escape sequences in a string in Python
Sometimes when I get input from a file or the user, I get a string with escape sequences in it. I would like to process the escape sequences in the same way that Python processes escape sequences in ...
175
votes
4
answers
215k
views
How do I escape double quotes in attributes in an XML String in T-SQL?
Pretty simple question - I have an attribute that I would like to have double quotes in. How do I escape them? I've tried
\"
""
\\"
And I've made the @xml variable both xml type and varchar(max) ...
175
votes
2
answers
56k
views
Escape characters with special meaning to the regex engine in PHP
Is there a PHP function that can escape RegEx patterns to prevent them from being applied when used inside another RegEx pattern?
I am looking for something along the lines of the C# Regex.Escape() ...
172
votes
4
answers
218k
views
How do I escape reserved words used as column names? MySQL/Create Table
I am generating tables from classes in .NET and one problem is a class may have a field name key which is a reserved MySQL keyword. How do I escape it in a create table statement? (Note: The other ...