escaping

Understanding awk delimiter - escaping in a regex-based field separator

送分小仙女□ 提交于 2019-12-10 10:52:25
问题 I have the following shell command: awk -F'\[|\]' '{print $2}' What is this command doing? Split into fields using as delimiter [sometext] ? E.g.: $ echo "this [line] passed to awk" | awk -F'\[|\]' '{print $2}' line Editor's note: Only Mawk, as used on Ubuntu by default, produces the output above. 回答1: The apparent intent is to treat literal [ and ] as field-separator characters, i.e., to split each input record into fields by each occurrence of [ and/or ] , which, with the sample line,

NSString strip regular \ escape characters how?

荒凉一梦 提交于 2019-12-10 10:43:25
问题 I need an efficient piece of code that strips escape characters. This is regular escapes not HTML escape characters. Example: "\"", "\\\\", "\", "\\" I want a general algorithm to strip any kind of escape sequences. Could use any utility like regular expression. (NSString*) unescape:(NSString*) string { .... } This is the answer I wrote: -(NSString*) unescape:(NSString*) string { for(int i = 0; i < string.length; i++) { char a = [string characterAtIndex:i]; if([string characterAtIndex:i] == '

Trying to stop bullets in textareas from entering my database as special characters

一曲冷凌霜 提交于 2019-12-10 10:36:57
问题 I am using this currently, but it doesn't seem to be working for bullets: function sanitizeMySQL($var){ $var = mysql_real_escape_string($var); $var = sanitizeString($var); return $var; } function sanitizeString($var) { $var = str_replace('•','•', $var); $var = htmlentities($var); $var = strip_tags($var); return $var; } This is what bullets show up like in my db after someone has submitted them through a textarea: • EDIT: This is now what I am getting: • . I do have bullets stored in my

VTD-XML seems to be spoiling escaped string in XML document

北战南征 提交于 2019-12-10 10:35:05
问题 I am working on an XML data set (the DrugBank database available here) where some fields contain escaped XML characters like "&", etc. To make the problem more concrete, here is an example scenario: <drugs> <drug> <drugbank-id>DB00001</drugbank-id> <general-references> # Askari AT, Lincoff AM: Antithrombotic Drug Therapy in Cardiovascular Disease. 2009 Oct; pp. 440–. ISBN 9781603272346. "Google books":http://books.google.com/books?id=iadLoXoQkWEC&pg=PA440. </general-references> . </drug>

Perfectly forwarding arguments in batch

余生颓废 提交于 2019-12-10 09:54:54
问题 I have a small python script: # args.py import sys; print(sys.argv) How can I write a .bat wrapper file that forwards all of the arguments to this script? To eliminate my shell from the tests, I'm going to invoke it as: import subprocess import sys def test_bat(*args): return subprocess.check_output(['args.bat'] + list(args), encoding='ascii') The obvious choice of batch file @echo off python args.py %* Works for simple cases: >>> test_bat('a', 'b', 'c') "['args.py', 'a', 'b', 'c']\n" >>>

Escape all double quotes inside a single quoted string with Regex [duplicate]

不羁岁月 提交于 2019-12-10 09:46:20
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Regular Expression to escape double quotes inside single quotes I need a regex (no other language!!, best would be perl syntax REGEX or PCRE syntax REGEX) to replace all double quotes " with a \" that are inside a single quoted string. This is an example string (part of a file): var baseUrl = $("#baseurl").html(); var head = '<div id="finishingDiv" style="background-image:url({baseUrl}css/userAd/images/out_main

Understanding input escaping in PHP

强颜欢笑 提交于 2019-12-10 08:04:55
问题 One thing that's always confused me is input escaping and whether or not you're protected from attacks like SQL injection. Say I have a form which sends data using HTTP POST to a PHP file. I type the following in an input field and submit the form: "Hello", said Jimmy O'Toole. If you print/echo the input on the PHP page that receives this POST data, it comes out as: \"Hello\", said Jimmy O\'Toole. This is the point where it gets confusing. If I put this input string into (My)SQL and execute

Escaping backslash in Postgresql

天涯浪子 提交于 2019-12-10 04:35:16
问题 I'm trying to write an sql function in Postgresql that will parse a file path. I want to return just the file name. I cannot get past getting an accurate text string in the function. Here is the function: Function: job_page("inputText" text) DECLARE $5 text; BEGIN $5 = quote_literal("inputText"); return $5; END When I run this: select job_page('\\CAD_SVR\CADJOBS\7512-CEDARHURST ELEMENTARY SCHOOL\7512-20.DWG') I get this result: "E'\\CAD_SVRCADJOBSé2-CEDARHURST ELEMENTARY SCHOOLé2-20.DWG'"

Quote POSIX shell special characters in Python output

拜拜、爱过 提交于 2019-12-10 04:35:08
问题 There are times that I automagically create small shell scripts from Python, and I want to make sure that the filename arguments do not contain non-escaped special characters. I've rolled my own solution, that I will provide as an answer, but I am almost certain I've seen such a function lost somewhere in the standard library. By “lost” I mean I didn't find it in an obvious module like shlex , cmd or subprocess . Do you know of such a function in the stdlib? If yes, where is it? Even a

Uri.EscapeUriString with square braces

让人想犯罪 __ 提交于 2019-12-10 03:34:07
问题 Something of a strange question but let's see what kind of response it gets... If I code a console app (VS 2013, .NET 4.5.1) and execute this line of code: Uri.EscapeUriString("[") I get this: [ However if I execute the same thing (well, technically Uri.EscapeUriString("[").Dump() ) in LINQPad on my machine I get this: %5B To further complicate things, according to this post Uri.EscapeUriString("[") should indeed return %5B .The post was written on 27/06/2012. I'm thinking that perhaps