Questions tagged [escaping]

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

Escaping is used for many purposes, such as providing representations of unprintable characters, changing font colors in terminals, or allowing the inclusion in a string of a character normally used to terminate the string, as well as allowing to output a character to user when that character can be used as a control or markup character.

Some of the more common uses of escaping

  • URL encoding to allow including characters such as / or ?, and others, in URL queries;
  • XML and HTML entities that can be used to encode special characters that, for example, would normally be used for markup purposes.
8255 questions
2128
votes
11 answers

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 do? If you are curious, like me, check the question…
Vinko Vrsalovic
  • 244,143
  • 49
  • 315
  • 361
982
votes
10 answers

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
  • 33,082
  • 26
  • 68
  • 92
811
votes
17 answers

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: value pairs. Therefore the HTML is created in the…
Swaff
  • 13,038
  • 4
  • 22
  • 26
753
votes
25 answers

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, gets pulled into
AJM
  • 30,452
  • 47
  • 147
  • 238
629
votes
26 answers

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/HTML injection attacks). I'm sure it's possible to…
Page
  • 9,605
  • 5
  • 34
  • 44
601
votes
15 answers

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: The name 'test' does not exist in the current…
ajay_whiz
  • 16,085
  • 3
  • 33
  • 44
590
votes
12 answers

Saving utf-8 texts with json.dumps as UTF8, not as \u escape sequence

Sample code: >>> import json >>> json_string = json.dumps("ברי צקלה") >>> print(json_string) "\u05d1\u05e8\u05d9 \u05e6\u05e7\u05dc\u05d4" The problem: it's not human readable. My (smart) users want to verify or even edit text files with JSON dumps…
Berry Tsakala
  • 11,390
  • 11
  • 52
  • 71
571
votes
1 answer

Escape string for use in Javascript regex

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 + ''); // [snip] perform search } But the…
too much php
  • 81,874
  • 33
  • 123
  • 133
557
votes
6 answers

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? This understandably doesn't work: string foo =…
kdt
  • 26,008
  • 26
  • 82
  • 130
549
votes
11 answers

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 source XML? I tried &, but this is decoded as the…
AJM
  • 30,452
  • 47
  • 147
  • 238
401
votes
6 answers

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 sentence and not have it break. What actually happens: …
jondykeman
  • 5,632
  • 3
  • 19
  • 20
391
votes
10 answers

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
  • 54,052
  • 71
  • 166
  • 213
386
votes
14 answers

Pass a PHP string to a JavaScript variable (and escape newlines)

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 JavaScript variable. Normally, I would just construct my…
David Laing
  • 7,395
  • 10
  • 31
  • 44
356
votes
9 answers

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': unknown revision or path not in the working tree. …
Jesse Atkinson
  • 8,386
  • 12
  • 38
  • 44
349
votes
15 answers

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="" sed "s/KEYWORD/$REPLACE/g" How can I escape the $REPLACE string so it would be safely accepted by sed as a…
Alexander Gladysh
  • 34,198
  • 31
  • 94
  • 153
1
2 3
99 100