backslash

Regex and escaped and unescaped delimiter

混江龙づ霸主 提交于 2019-12-18 06:01:10
问题 question related to this I have a string a\;b\\;c;d which in Java looks like String s = "a\\;b\\\\;c;d" I need to split it by semicolon with following rules: If semicolon is preceded by backslash, it should not be treated as separator (between a and b ). If backslash itself is escaped and therefore does not escape itself semicolon, that semicolon should be separator (between b and c ). So semicolon should be treated as separator if there is either zero or even number of backslashes before it.

sh read command eats slashes in input?

℡╲_俬逩灬. 提交于 2019-12-18 05:28:07
问题 Perhaps easiest to explain with an example: $ echo '\&|' \&| $ echo '\&|' | while read in; do echo "$in"; done &| It seems that the "read" command is interpreting the slashes in the input as escapes and is removing them. I need to process a file line by line without changing its contents and I'm not sure how to stop read from being smart here. Any ideas? 回答1: Accrding to: http://www.vias.org/linux-knowhow/bbg_sect_08_02_01.html : -r If this option is given, backslash does not act as an escape

Why I need to double-escape (use 4 \) to find a backslash ( \ ) in pure SQL?

对着背影说爱祢 提交于 2019-12-18 05:12:15
问题 I do not understand this MySQL behaviour : if I want to display a\b, I can just select "a\\b" which work without problem : mysql> select "a\\b"; +-----+ | a\b | +-----+ | a\b | +-----+ 1 row in set (0.05 sec) But if I wnat to search a string containing a \ in a table using LIKE, I need to double-escape my "\". Why ? Here is an example. We prepare a small table. create table test ( test varchar(255) ); insert into test values ( "a\\b" ) , ( "a\\b\\c" ) , ( "abcd" ); mysql> select * from test;

Replacing double backslashes with single backslash

半腔热情 提交于 2019-12-18 05:04:43
问题 I have a string "\\u003c", which belongs to UTF-8 charset. I am unable to decode it to unicode because of the presence of double backslashes. How do i get "\u003c" from "\\u003c"? I am using java. I tried with, myString.replace("\\\\", "\\"); but could not achieve what i wanted. This is my code, String myString = FileUtils.readFileToString(file); String a = myString.replace("\\\\", "\\"); byte[] utf8 = a.getBytes(); // Convert from UTF-8 to Unicode a = new String(utf8, "UTF-8"); System.out

Raw string and regular expression in Python

て烟熏妆下的殇ゞ 提交于 2019-12-18 04:19:09
问题 I have some confusions regarding raw string in the following code: import re text2 = 'Today is 11/27/2012. PyCon starts 3/13/2013.' text2_re = re.sub(r'(\d+)/(\d+)/(\d+)', r'\3-\1-\2', text2) print (text2_re) #output: Today is 2012-11-27. PyCon starts 2013-3-13. print (r'(\d+)/(\d+)/(\d+)') #output: (\d+)/(\d+)/(\d+) As how I understand the raw string, without r , the \ is treated as escape character; with r , the backslash \ is treated as itself literally. However, what I cannot understand

Error with double backslash in Windows path in Python

北战南征 提交于 2019-12-17 20:25:32
问题 I want to work with paths in Windows in Python 3.3, but I have an error: FileNotFoundError: [Errno 2] No such file or directory: 'E:\\dir\\.project' The problem is the double backslash. I read the solution using r. def f(dir_from): list_of_directory = os.listdir(dir_from) for element in list_of_directory: if os.path.isfile(os.path.join(dir_from, element)): open(os.path.join(dir_from, element)) f(r'E:\\dir') I have this error again FileNotFoundError: [Errno 2] No such file or directory: 'E:\

Passing meta-characters to Python as arguments from command line

佐手、 提交于 2019-12-17 20:07:49
问题 I'm making a Python program that will parse the fields in some input lines. I'd like to let the user enter the field separator as an option from the command line. I'm using optparse to do this. I'm running into the problem that entering something like \t will separate literally on \t , rather than on a tab, which is what I want. I'm pretty sure this is a Python thing and not the shell, since I've tried every combo of quotes, backslashes, and t 's that I can think of. If I could get optparse

Converting backslashes into forward slashes using javascript does not work properly?

北慕城南 提交于 2019-12-17 16:34:33
问题 I have a javascript variable comming from legacy system with backslashes into forward slashes: '/46\465531_Thumbnail.jpg' and I am trying to convert into this: '/46/465531_Thumbnail.jpg' . There is no way to fix the problem on the legacy system. Here is the command I am running on IE8 browser: javascript:alert("/46\465531_Thumbnail.jpg".replace(/\\/g,"/")); as response I get: --------------------------- Message from webpage --------------------------- /46&5531_Thumbnail.jpg ------------------

How to remove backslash on json_encode() function?

元气小坏坏 提交于 2019-12-17 11:27:10
问题 How to remove the (\) backslash on a string? when using echo json_encode() ? For example: <?php $str = "$(\"#output\").append(\"<p>This is a test!</p>\")"; echo json_encode($str); ?> note: When you echo $str, there will be no problem... but when you echo out using json_encode() , the (\) backslash will show up. Is there a way to solve this? 回答1: json_encode($response, JSON_UNESCAPED_SLASHES); 回答2: Since PHP 5.4 there are constants which can be used by json_encode() to format the json reponse

Url stored in MySQL returns with extra backslash for each forward slash ( a/b.png => a\/b.png)

醉酒当歌 提交于 2019-12-13 21:25:17
问题 I have a MySql database with a URL field that has normal URLs with forward slashes. When I get the URL data with PHP web service it shows up with a backward slash for each forward slash: http://example.com/iphone/images/test.png shows as http:\/\/example.com\/iphone\/images\/test.png What could be the problem? Here is the function that gets my data. function getdata() { // Check for required parameters if (isset($_POST["genre"])) { // Put parameters into local variables $genre = $_POST["genre