quotes

Regex for quoted string with escaping quotes

这一生的挚爱 提交于 2019-11-25 23:49:20
问题 How do I get the substring \" It\'s big \\\"problem \" using a regular expression? s = \' function(){ return \" It\\\'s big \\\"problem \"; }\'; 回答1: /"(?:[^"\\]|\\.)*"/ Works in The Regex Coach and PCRE Workbench. Example of test in JavaScript: var s = ' function(){ return " Is big \\"problem\\", \\no? "; }'; var m = s.match(/"(?:[^"\\]|\\.)*"/); if (m != null) alert(m); 回答2: This one comes from nanorc.sample available in many linux distros. It is used for syntax highlighting of C style

bash regex with quotes?

巧了我就是萌 提交于 2019-11-25 23:46:48
问题 The following code number=1 if [[ $number =~ [0-9] ]] then echo matched fi works. If I try to use quotes in the regex, however, it stops: number=1 if [[ $number =~ \"[0-9]\" ]] then echo matched fi I tried \"\\[0-9\\]\" , too. What am I missing? Funnily enough, bash advanced scripting guide suggests this should work. Bash version 3.2.39. 回答1: It was changed between 3.1 and 3.2. Guess the advanced guide needs an update. This is a terse description of the new features added to bash-3.2 since

What is the difference between single and double quotes in SQL?

孤街醉人 提交于 2019-11-25 23:24:49
问题 What is the difference between single quotes and double quotes in SQL? 回答1: Single quotes are used to indicate the beginning and end of a string in SQL. Double quotes generally aren't used in SQL, but that can vary from database to database. Stick to using single quotes. That's the primary use anyway. You can use single quotes for a column alias — where you want the column name you reference in your application code to be something other than what the column is actually called in the database

Difference between single and double quotes in Bash

房东的猫 提交于 2019-11-25 22:51:14
问题 In Bash, what are the differences between single quotes ( \'\' ) and double quotes ( \"\" )? 回答1: Single quotes won't interpolate anything, but double quotes will. For example: variables, backticks, certain \ escapes, etc. Example: $ echo "$(echo "upg")" upg $ echo '$(echo "upg")' $(echo "upg") The Bash manual has this to say: 3.1.2.2 Single Quotes Enclosing characters in single quotes ( ' ) preserves the literal value of each character within the quotes. A single quote may not occur between

How to enter quotes in a Java string?

我与影子孤独终老i 提交于 2019-11-25 22:46:31
问题 I want to initialize a String in Java, but that string needs to include quotes; for example: \"ROM\" . I tried doing: String value = \" \"ROM\" \"; but that doesn\'t work. How can I include \" s within a string? 回答1: In Java, you can escape quotes with \ : String value = " \"ROM\" "; 回答2: In reference to your comment after Ian Henry's answer, I'm not quite 100% sure I understand what you are asking. If it is about getting double quote marks added into a string, you can concatenate the double

Regex to pick commas outside of quotes

*爱你&永不变心* 提交于 2019-11-25 21:58:48
问题 I\'m not quite sure if this is possible, so I turn to you. I would like to find a regex that will pick out all commas that fall outside quote sets. For example: \'foo\' => \'bar\', \'foofoo\' => \'bar,bar\' This would pick out the single comma on line 1, after \'bar\', I don\'t really care about single vs double quotes. Has anyone got any thoughts? I feel like this should be possible with readaheads, but my regex fu is too weak. 回答1: This will match any string up to and including the first

Expansion of variable inside single quotes in a command in Bash

五迷三道 提交于 2019-11-25 21:57:27
问题 I want to run a command from a bash shell script which has single quotes and some other commands inside the single quotes and a variable. e.g. repo forall -c \'....$variable\' In this format, $ is escaped and the variable is not expanded. I tried the following variations but they were rejected: repo forall -c \'....\"$variable\" \' repo forall -c \" \'....$variable\' \" \" repo forall -c \'....$variable\' \" repo forall -c \"\'\" ....$variable \"\'\" If I substitute the value in place of the

Escaping Strings in JavaScript

无人久伴 提交于 2019-11-25 21:57:05
Does JavaScript have a built-in function like PHP's addslashes (or addcslashes ) function to add backslashes to characters that need escaping in a string? For example, this: This is a demo string with 'single-quotes' and "double-quotes". ...would become: This is a demo string with \'single-quotes\' and \"double-quotes\". Paolo Bergantino http://locutus.io/php/strings/addslashes/ function addslashes( str ) { return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0'); } Storm You can also try this for the double quotes: JSON.stringify(sDemoString).slice(1, -1); JSON.stringify('my

How to output MySQL query results in CSV format?

久未见 提交于 2019-11-25 21:53:04
问题 Is there an easy way to run a MySQL query from the Linux command line and output the results in CSV format? Here\'s what I\'m doing now: mysql -u uid -ppwd -D dbname << EOQ | sed -e \'s/ /,/g\' | tee list.csv select id, concat(\"\\\"\",name,\"\\\"\") as name from students EOQ It gets messy when there are a lot of columns that need to be surrounded by quotes, or if there are quotes in the results that need to be escaped. 回答1: From http://www.tech-recipes.com/rx/1475/save-mysql-query-results

Insert text with single quotes in PostgreSQL

允我心安 提交于 2019-11-25 21:49:38
问题 I have a table test(id,name) . I need to insert values like: user\'s log , \'my user\' , customer\'s . insert into test values (1,\'user\'s log\'); insert into test values (2,\'\'my users\'\'); insert into test values (3,\'customer\'s\'); I am getting an error if I run any of the above statements. If there is any method to do this correctly please share. I don\'t want any prepared statements. Is it possible using sql escaping mechanism? 回答1: String literals Escaping single quotes ' by