Skip to main content

Questions tagged [escaping]

Escaping is the process of applying an alternate meaning to a character or set of characters.

Filter by
Sorted by
Tagged with
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 ...
Vinko Vrsalovic's user avatar
  • 337k
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?
Julius A's user avatar
  • 39.1k
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 ...
Berry Tsakala's user avatar
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: ...
Swaff's user avatar
  • 13.6k
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 &...
AJM's user avatar
  • 32.4k
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 ...
too much php's user avatar
  • 90.3k
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: ...
ajay_whiz's user avatar
  • 17.9k
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/...
Page's user avatar
  • 9,975
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: &amp;. How do I escape this ampersand in the ...
AJM's user avatar
  • 32.4k
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? ...
kdt's user avatar
  • 28.3k
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': ...
Jesse Atkinson's user avatar
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'
Mike's user avatar
  • 60.1k
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 ...
jondykeman's user avatar
  • 6,242
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 ...
Alexander Gladysh's user avatar
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:...
danieltahara's user avatar
  • 4,913
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 ...
David Laing's user avatar
  • 7,655
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: #...
Pedro Lobito's user avatar
  • 97.5k
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 &...
Matt's user avatar
  • 32.1k
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 ...
Barth's user avatar
  • 15.5k
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 ...
Chris's user avatar
  • 3,762
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 ...
srgb's user avatar
  • 5,073
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 ...
Travis's user avatar
  • 3,529
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" ...
fedorqui's user avatar
  • 285k
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 ...
Joseph Turian's user avatar
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 ...
Ben Lings's user avatar
  • 29.1k
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\*.*
faressoft's user avatar
  • 19.5k
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)...
akif's user avatar
  • 12.2k
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 ...
Matt Dawdy's user avatar
  • 19.6k
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 ...
harpax's user avatar
  • 6,076
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 = ...
Sandeepan Nath's user avatar
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 &...
jpm's user avatar
  • 16.7k
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 ...
Ravi's user avatar
  • 8,109
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?
Muhammad Hewedy's user avatar
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(...
Hallgrim's user avatar
  • 15.4k
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 ...
sjw's user avatar
  • 2,633
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 ...
Srikant 's user avatar
  • 2,221
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 ...
Matthew's user avatar
  • 3,194
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 &#64; sequence, but that didn't work.
JayL's user avatar
  • 2,869
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 ...
Bart van Heukelom's user avatar
206 votes
5 answers
357k views

Why shouldn't `&apos;` 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 ...
brad's user avatar
  • 75k
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. ...
Colin Grogan's user avatar
  • 2,702
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?
user4951's user avatar
  • 32.8k
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 ...
weston's user avatar
  • 2,878
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 ...
Slater Victoroff's user avatar
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; ...
Peter Mortensen's user avatar
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 ...
Behrang Saeedzadeh's user avatar
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 ...
dln385's user avatar
  • 11.9k
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) ...
Tom Ritter's user avatar
  • 101k
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() ...
vfclists's user avatar
  • 19.8k
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 ...
user avatar

1
2 3 4 5
181