escaping

How do I escape backslashes in a sed script embedded in a bash script

戏子无情 提交于 2019-12-10 02:58:27
问题 I want to edit a file via a sed script in a bash script. I want this to be easy to maintain later; easy to understand and modify. The replacement string looks like: PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\]' In a perfect world, it would like this: sed -i "s/^PS1.*$/PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\]'/g" /etc/skel/.bashrc The problem is that bash and sed are stripping out the \ giving the following result in the file: PS1='[e[1;32m][@h W]$[e[0m]' Obviously single quotes can't be used. A brute

How do you correctly escape a document name in .NET?

孤人 提交于 2019-12-10 02:44:54
问题 We store a bunch of weird document names on our web server (people upload them) that have various characters like spaces, ampersands, etc. When we generate links to these documents, we need to escape them so the server can look up the file by its raw name in the database. However, none of the built in .NET escape functions will work correctly in all cases. Take the document Hello#There.docx : UrlEncode will handle this correctly: HttpUtility.UrlEncode("Hello#There"); "Hello%23There" However,

Ruby: Escaping special characters in a string

帅比萌擦擦* 提交于 2019-12-10 02:28:57
问题 I am trying to write a method that is the same as mysqli_real_escape_string in PHP. It takes a string and escapes any 'dangerous' characters. I have looked for a method that will do this for me but I cannot find one. So I am trying to write one on my own. This is what I have so far (I tested the pattern at Rubular.com and it worked): # Finds the following characters and escapes them by preceding them with a backslash. Characters: ' " . * / \ - def escape_characters_in_string(string) pattern =

At witt's end… Javascript won't replace '\n'!

白昼怎懂夜的黑 提交于 2019-12-10 02:04:34
问题 I've been going at this problem for a solid couple hours now and having zero luck. No clue how this is even possible; I'll try to summarize. I'm using TinyMCE to insert new content to a DB, that content is being sent back as an AJAX response after it is inserted into the DB and then shown on the page, replacing some old content. All of that isn't really relevant (as far as I can tell) to the problem, but it serves as a background to the problem. Anyhow, the response text has '\n'

How to pass in a null character in a command line argument in C?

*爱你&永不变心* 提交于 2019-12-10 01:10:06
问题 I would still like to know how to pass in a null character as a command line argument, maybe so that a single string can be passed in as an argument in the form: "to\0be\0or\0not\0to\0be\0" And then parse it. However the program would treat this string as: "to\\0be\\0or\\0not\\0to\\0be\\0" How can I work around this? Is there any way? 回答1: You cannot. The C program receives arguments as zero-terminated strings. Such a string cannot contain a null character, by definition. If you want to pass

Replace a question mark (?) with (\\?)

隐身守侯 提交于 2019-12-10 00:40:15
问题 I am trying to define a pattern to match text with a question mark (?) inside it. In the regex the question mark is considered a 'once or not at all'. So can i replace the (?) sign in my text with (\\?) to fix the pattern problem ? String text = "aaa aspx?pubid=222 zzz"; Pattern p = Pattern.compile( "aspx?pubid=222" ); Matcher m = p.matcher( text ); if ( m.find() ) System.out.print( "Found it." ); else System.out.print( "Didn't find it." ); // Always prints. 回答1: You need to escape ? as \\?

Read escaped quote as escaped quote from xml

泪湿孤枕 提交于 2019-12-09 23:25:42
问题 I load xml file into DOM model and analyze it. The code for that is: public class MyTest { public static void main(String[] args) { Document doc = XMLUtils.fileToDom("MyTest.xml");//Loads xml data to DOM Element rootElement = doc.getDocumentElement(); NodeList nodes = rootElement.getChildNodes(); Node child1 = nodes.item(1); Node child2 = nodes.item(3); String str1 = child1.getTextContent(); String str2 = child2.getTextContent(); if(str1 != null){ System.out.println(str1.equals(str2)); }

jQuery parseJSON

喜夏-厌秋 提交于 2019-12-09 23:07:26
问题 Receiving this error ("JSON.parse: unexpected character") when I try to parse a JSON validated string. It works perfectly when I remove the characters that need escaped (style="width:400px;"). What am I missing? Is there a unique way to escape characters before you use parseJSON? var $cookieString = '{"youTabItems": { "youTab-001": <p style=\"width:400px;\">Welcome to my test</p>, "youTab-002": "test02Value", "youTab-003": "test03Value" }}'; var $myCookieString = $.parseJSON($cookieString);

Json.Parse escape newline characters

怎甘沉沦 提交于 2019-12-09 17:59:03
问题 I have a page where I am trying to parse following json string using JSON.parse '[{"Name":"Eggs","Complete":false,"Notes":"Notes here\n"},{"Name":"Sugar","Complete":false,"Notes":null}]' But following code gives error "Uncaught SyntaxError: Unexpected token" var groceriesJson = JSON.parse(jsonString); Then I came to know that its because of \n in json string. So I did try this solution. But no luck. Still same error "Uncaught SyntaxError: Unexpected token" function escapeSpecialChars

RegEx: Don't match a certain character if it's inside quotes

我的梦境 提交于 2019-12-09 16:53:43
问题 Disclosure: I have read this answer many times here on SO and I know better than to use regex to parse HTML. This question is just to broaden my knowledge with regex. Say I have this string: some text <tag link="fo>o"> other text I want to match the whole tag but if I use <[^>]+> it only matches <tag link="fo> . How can I make sure that > inside of quotes can be ignored. I can trivially write a parser with a while loop to do this, but I want to know how to do it with regex. 回答1: Regular