FAQ Database Discussion Community


Dealing with backslash as a command line argument in Python

python,string,command-line-arguments,backslash
I know about escaping backslashes in programming. However I'm passing in a command line argument into a Python program to parse. Whitespace is irrelevant, however via the command line, whitespace does matter. So I am trying to concatenate all argv[] arguments except the first element into a string to then...

How to use '\' in Python lookbehind assertion regex (?<=\\) to match C++-like quoted strings

python,regex,backslash,lookbehind
How can I match r'\a' in Python using lookbehind assertion? Actually, I need to match C++ strings like "a \" b" and "str begin \ end" I tried: >>> res = re.compile('(?<=\)a') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/re.py", line 190, in compile return...

Convert single backslash to double backslash

python,string,python-2.7,backslash
I have a list containing directories: ("..\b\c.txt", "..\b\d.txt"). I was planning to use .split() method to have another list of the directory components separated by "\", but I'm not having success mostly due to "\" usage. Thus, the final result will be something like this ("a", "b, "c.txt") ... I...

How to change backslash to double backslash?

c#,sql-server,string,tsql,backslash
My TSQL query return a string like this : a\path\to\file.xml And I want to put it in a string like this : string path = reader.GetString(0); (return the query result of the first field => "a\path\to\file.xml") so when I want to use path I have got this : Console.WriteLine(path); //Output...

Can't replace '\n' with '\\' for whatever reason

sed,backslash,tr
I have a whole bunch of files, and I wish to change something like this: My line of text My other line of text Into My line of text\\ My other line of text Seems simple, but somehow it isn't. I have tried sed s,"\n\n","\\\\\n", as well as tr '\n'...

Backslash using for escaping qute regenerate after asigning String

c#,asp.net,backslash,htmltextwriter,stringwriter
in ToString methode of my Entity, i try to generate a informational string includes quotes. so i use backslash before quote and everything is good until i try to assign return value to a string variable and after that all backslash comeback .here is the ToString function: public override string...

Raw string and regular expression in Python

python,regex,escaping,backslash,rawstring
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 \...

removing double backslash from string containing some of them

string,haskell,replace,backslash
I'm having trouble cause I can't define a function to do this: Input: "(case (+ 5 5) ((4 9 1) 'd64)\\n((1 2) 'pepito)\\n((10) 'jorgito)" Output: "(case (+ 5 5) ((4 9 1) 'd64)\n((1 2) 'pepito)\n((10) 'jorgito)" I've tried this and many other, without success: import Data.List.Split (splitOn) import Data.List (intersperse)...

(swift) remove “\” character from string?

string,swift,backslash
I have string which contains few \ and I want to remove all of them. can anyone tell me how can I do that. I have already tried stringByReplacingOccurrencesOfString but it's not working out for me.

POSIX Shell backslash confusion

shell,sh,backslash
I am trying to create a shell script with a simple functionality, but it seems I can not wrap my head about how to handle backslashes correctly. One of my functions look like this: #!/bin/sh func() { cmd="$*" printf "%s\n" "$cmd" echo -e $cmd } func '%{NAME}\\n' This is the...

PHP remove weird backslashes from url

php,string,strip,backslash
i'm working on a small scraper for fun and when I grab some image urls from certain sites they come back really weird. For example: scraped url: https:\/\/cdn1.vox-cdn.com\/thumbor\/zN9XawbQJgFPkuAcA2JEGgqApm8=\/cdn0.vox-cdn.com\/uploads\/chorus_asset\/file\/3700712\/tomorrowland54fdf04f23efb_2040.0.jpg desired url: https://cdn1.vox-cdn.com/thumbor/zN9XawbQJgFPkuAcA2JEGgqApm8=/cdn0.vox-cdn.com/uploads/chorus_asset/file/3700712/tomorrowland54fdf04f23efb_2040.0.jpg it's adding unnecessary backslashes, so that url doesn't work when you...

how does apache commons-cli parses \\t character

shell,command-line,command-line-interface,backslash,apache-commons-cli
I need to pass tab as an argument in commons-cli. When I give the argument as "\\t", the command line parser parses it as "\t" character itself but not TAB ( ) white space. How can I achieve this? Edit : As suggested by @centic, updating the question with how...

Working with the characters backslash and curly brackets in regular expressions in Python

python,regex,backslash,curly-brackets
I am using regular expressions to recognize the lines containing \begin{frame} in .tex files. Below is my code: #!/usr/bin/python import re,sys def isEven(num): res = [False,True][bool(num % 2 == 0)] return res textin = open(sys.argv[1]).readlines() nline = 0 pat = r'\b\begin{frame}\b' for line in textin: line = line.strip(' ') #print...