FAQ Database Discussion Community

PHP remove weird backslashes from url

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...

Raw string and regular expression in Python

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

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)...

Dealing with backslash as a command line argument in Python

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...

POSIX Shell backslash confusion

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...

Convert single backslash to double 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...

(swift) remove “\” character from string?

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.

how does apache commons-cli parses \\t character

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...

How to change backslash to double 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...

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

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...

Backslash using for escaping qute regenerate after asigning String

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...

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

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'...

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

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...