escaping

Grep and regex - why am I escaping curly braces?

放肆的年华 提交于 2019-12-17 16:30:44
问题 I'm deeply puzzled by the way grep seems to parse a regex: $ echo "@NS500287" | grep '^@NS500[0-9]{3}' #nothing $ echo "@NS500287" | grep '^@NS500[0-9]\{3\}' @NS500287 That can't be right. Why am I escaping curly brackets that are part of a "match the previous, N times" component (and not, say, the square brackets as well)? Shouldn't escaping be necessary only when I'm writing a regex that actually matches { and } as literal characters in the query string? More of a cri de coeur than anything

When should I use escape and safe in Django's template system?

 ̄綄美尐妖づ 提交于 2019-12-17 16:28:07
问题 If I have a box where people put comments, and then I display that comment like this...should I escape? {{ c.title }} 回答1: Actually, it depends. Django's templating engine does escaping automatically, so you don't really need to escape. If you add template filter "safe" like {{c.title|safe}} then you do need to worry about things like html injection, because "safe" marks the string as such and it means that it won't be escaped. There is also an {% autoescape on %}...{% endautoescape %}

How to parse strace in shell into plain text?

假装没事ソ 提交于 2019-12-17 16:27:48
问题 I've trace log generated by strace command like on running PHP by: sudo strace -e sendto -fp $(pgrep -n php) -o strace.log And the output looks like: 11208 sendto(4, "set 29170397297_-cache-schema 85 0 127240\r\n\257\202\v\0?\0\0\0\2\27\10stdClass\24\7\21\3cid\21\6schema\21\4d\37ata\25\n\247\21\5block\24\6\21\6fields\24\f\21\3bid\24\2\5\21\4type 0\37erial\21\10not null\5\21\6module\24\4\16\7\21\7va\37rchar\21\6length\6@\16\t\5\21\7default\r\21\5de\2lta@ \5\16\v\16\f\6 \35\7\16\r\21\0010\21\5t

How do I escape a Unicode character in my Objective-C source code?

杀马特。学长 韩版系。学妹 提交于 2019-12-17 16:24:37
问题 I feel incredibly stupid for asking this, but the documentation and Google are giving me no love at all. I have a Unicode character I want to insert into a string literal in the source code of my iPhone app. I know its hex value. What is the proper escape sequence to use? And for that matter, what obvious source of information am I overlooking that would have told me this? 回答1: Example: NSString *stuff = @"The Greek letter Beta looks like this: \u03b2, and the emoji for books looks like this:

\x Escape in Java?

限于喜欢 提交于 2019-12-17 16:24:25
问题 I was wondering if there is a similar hex (\x) escape in Java like there is in C++. For example: char helloworld[] = "\x48\x45\x4C\x4C\x4F\x20\x57\x47\x52\x4C\x44"; printf("%s", helloworld); There is no hex (\x) escape in Java from what it appears so far. Is there an alternative that is just as easy to use without having to concat a bunch of hex numbers together? 回答1: Strings in Java are always encoded in UTF-16, so it uses a Unicode escape: \u0048 . Octal characters are supported as well:

Escaping MYSQL command lines via Bash Scripting

孤人 提交于 2019-12-17 16:17:01
问题 PHP has mysql_real_escape_string() to correctly escape any characters that might cause problems. What is the best way to mimic this functionality for BASH? Is there anyway to do prepared mysql statements using bash? This seems to be the best way. Most of my variables won't (shouldn't) have special characters, however I give the user complete freedom for their password. It may include characters like ' and ". I may be doing multiple SQL statements so I'll want to make a script that takes in

Notepad++ Regex Backreference syntax in Search/Replace - \1 or $1

跟風遠走 提交于 2019-12-17 16:01:55
问题 I have tried to use the Notepad++ Search/Replace with a Regular Expression to replace specific words with shorter versions of those words. I used the following regex to match every word that ends with er (but not er as a word) - and replace the matching words with the same words minus the ending r , using a backreference: Find what: ([a-zA-z]+e)r Replace with: $1 But it doesn't replace the matching words, even though it finds them. However, if I change the backreference syntax to this:

Escaping a single quotation within SQL query

最后都变了- 提交于 2019-12-17 15:42:29
问题 I have a table companies , which has two columns named name and address . By running the following code, new data are inserted into the table: my_name = "my company name" my_address = "ABC" query = "INSERT INTO companies (name,address) VALUES ('#{my_name}','#{my_address}');" ActiveRecord::Base.connection.execute(query); If I change my_name value from "my company name" to "John's company" , I will get a syntax error. This is because the query becomes: "INSERT INTO companies (name,address)

How can I put double quotes inside a string within an ajax JSON response from php?

廉价感情. 提交于 2019-12-17 15:38:22
问题 I receive a JSON response in an Ajax request from the server. This way it works: { "a" : "1", "b" : "hello 'kitty'" } But I did not succeed in putting double quotes around kitty . When I convert " to \x22 in the Ajax response, it is still interpreted as " by JavaScript and I cannot parse the JSON. Should I also escape the \ and unescape later (which would be possible)? How to do this? Edit: I am not sure if i expressed it well: I want this string inside of "b" after the parse: hello "kitty"

Escaping double quotes in JavaScript onClick event handler

流过昼夜 提交于 2019-12-17 15:37:38
问题 The simple code block below can be served up in a static HTML page but results in a JavaScript error. How should you escape the embedded double quote in the onClick handler (i.e. \"xyz)? Note that the HTML is generated dynamically by pulling data from a database, the data of which is snippets of other HTML code that could have either single or double quotes. It seems that adding a single backslash ahead of the double quote character doesn't do the trick. <script type="text/javascript">