Questions tagged [backslash]

The backslash character \ (not to be confused with slash /) is used in many languages as an escape character to modify the meaning of the following character. It is also the directory separator in file paths under DOS and Windows.

The backslash character \ is a mirror version of the slash character /, created for use in computing. Its meaning depends on the context.

  • In many languages, \ followed by a character that has a special meaning makes the next character lose its special meaning. This is especially true inside string literals and regular expressions : for example, in many languages, "a\\b\"" represents the 4-character string a\b".
  • Sometimes \ gives the next character a special meaning. This is mostly the case when \ is followed by a letter or digit in a string literal, where it can be used to specify a control character or other special character. For example, \n specifies a newline in many languages, and \123 often specifies the character whose octal value is 123 (but note that some languages have different rules).
  • In DOS and Windows , the \ character is the directory (folder) separator in file paths. For example, c:\windows\cmd.exe is the file called cmd.exe in the directory called windows at the root of the c: drive.
  • In (La)TeX , \ starts a command name.
  • In Haskell , \ introduces a lambda expression .
991 questions
9
votes
1 answer

error: bad escape (end of pattern) at position 0 while trying to replace to backslah

I need to replace single backslash in my string. I'm trying to perform '\' but it gives with me double backslash. When i'm performing '\' it throw error bad escape (end of pattern) at position 0 string =…
user3193813
  • 147
  • 1
  • 1
  • 8
9
votes
1 answer

Why do I have to use double backslashes for file-paths in code?

In my program I'm trying to open a file, for example C:\unescaped\backslashes.txt, but it fails to open! Why? What is this? This is a collection of common Q&A. This is also a Community Wiki, so everyone is invited to participate in maintaining…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
9
votes
2 answers

Eclipse project.properties backslash paths considered harmful

I am working in a team that is developing Android software. Some team members use Windows, some use Macs, and I have been known to use Linux. Everyone uses Eclipse. Eclipse writes a file called project.properties; here's an example. The important…
steveha
  • 74,789
  • 21
  • 92
  • 117
8
votes
5 answers

Regex and escaped and unescaped delimiter

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…
lstipakov
  • 3,138
  • 5
  • 31
  • 46
8
votes
4 answers

Raw string and regular expression in Python

I'm confused about 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…
fluency03
  • 2,637
  • 7
  • 32
  • 62
8
votes
1 answer

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[]…
tfbbt8
  • 325
  • 4
  • 13
8
votes
3 answers

In the JSON Response String contains auto-added Backslashes

I am calling a webservice to get a JSON string response and It contains backslashes which is not in original string. Below is my code for requesting a JSON string object which is: {"name":"Name","id":1} protected String…
Jahanzeb Khan
  • 81
  • 1
  • 1
  • 5
8
votes
1 answer

Double backslash in cmd directory handling

Due to sometimes empty variables within a cmd-script I get directory definitions with doubled backslashes (\\). Example: SET "Mp3OutDir=%Mp3Root%\%AlbumDir%\%AlbumArtist1stChar%\%AlbumArtistSort_VDN%\[%Year%] %Album_VDN%" leads, if %AlbumDir% is…
cmdquestion
  • 83
  • 1
  • 3
8
votes
7 answers

Replacing double backslashes with single backslash

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…
Vinay thallam
  • 391
  • 1
  • 7
  • 17
8
votes
5 answers

Ignore escape sequences in ASCII art

For my command-line-interfaces it's often nice to have a little ASCII art in the beginning, but those often contain many backslashes. For example: System.out.println(" _____ _______ _____ _ __ "); System.out.println(" / ____|__ __|/\ /…
trichner
  • 840
  • 1
  • 11
  • 22
7
votes
1 answer

How to use the backslash operator in Julia?

I am currently trying to invert huge matrices of order 1 million by 1 million and I figured that the Backslash operator will be helpful in doing this. Any idea as to how it's implemented?. I did not find any concrete examples so any help is much…
Czar'
  • 91
  • 1
  • 4
7
votes
2 answers

NodeJS escaping back slash

I am facing some issues with escaping of back slash, below is the code snippet I have tried. Issues is how to assign a variable with escaped slash to another variable. var s = 'domain\\username'; var options = { user : '' }; options.user = …
Dipak
  • 6,532
  • 8
  • 63
  • 87
7
votes
2 answers

php regex replace double backslash with single

I do not want to use stripslashes() because I only want to replace "\\" with "\". I tried preg_replace("/\\\\/", "\\", '2\\sin(\\pi s)\\Gamma(s)\\zeta(s) = i\\oint_C \\frac{-x^{s-1}}{e^x -1} \\mathrm{d}x'); Which to my disapointment returns:…
Mikkel Rev
  • 863
  • 3
  • 12
  • 31
7
votes
1 answer

Postgres. How to convert string that contains '\' to bytea?

I have string 'test\data' or just one backslash symbol '\'. How it convert to bytea?
marvinorez
  • 593
  • 4
  • 7
7
votes
1 answer

Getting rid of backslash at the end of wrapped lines (for copy-paste)

Emacs in text-mode puts a \ character (backslash) at the end of a wrapped line. I would like to not have that displayed, so I can copy-paste from such a window into another one, without getting the \ in the pasted text. I'm sure there is an easy…
Stefan Ludwig
  • 333
  • 2
  • 8