Backslashes
Backslashes
[A list of the names of different numbers of backslashes. After each "item" there is a gray line to the text describing each item. As the text is aligned above each other, the lines becomes shorter as the sequence of backslashes becomes longer until there is just a line with the length of a single hyphen for the last item. There are 1 to 8 backslashes and then 11 plus "..." in the last entry.] \ ------------ Backslash \\ ----------- Real backslash \\\ ---------- Real real backslash \\\\ ---------- Actual backslash, for real this time \\\\\ --------- Elder backslash \\\\\\ -------- Backslash which escapes the screen and enters your brain \\\\\\\ ------- Backslash so real it transcends time and space \\\\\\\\ ------ Backslash to end all other text \\\\\\\\\\\... - The true name of Ba'al, the Soul-Eater
The title text when first published was
It was changed within a few days to
The original title text seems to be more relevant to the comic, but the revised title text seems to make more sense as a legitimate command line due to the way backslashes are interpreted in regular expressions. See the Discussion below for much more on the topic.

Most programming languages use the concept of a string literal, which is just a text between some delimiters, usually quotes. For example, "Hello, world" is a string literal. The text being represented is Hello, world without the quotes. However, the quotes are also written to mark the beginning and end of the string. This is a problem when the text itself contains a quote, as in "This is a "quoted" string". The quotes around the word "quoted" are intended to be part of the text, but the language processor will likely confuse it for the end of the string, which would thus be two strings with quoted outside these strings (probably resulting in a syntax error).
To avoid this problem, an escape character (usually a backslash) is prepended to non-string-terminating quotes. So, the previous text would be written as "This is a \"quoted\" string". The language processor will substitute every occurrence of \" with only the quote character, and the string terminates at the quote character which does not immediately follow a backslash. In this case the resulting text string would be This is a "quoted" string as intended.
However, the problem now is that the intended text might contain a backslash itself. For example, the text "C:\" will now be interpreted as an unterminated string containing a quote character. To avoid this, literal backslashes also are escaped with a second backslash, i.e. instead of "C:\" we write "C:\\", where the language processor interprets \\ as one single backslash and the quote terminates the string to give C:\ as the output.
This doubling of backslashes happens in most programming and scripting languages, but also in other syntactic constructs such as regular expressions . So, when several of these languages are used in conjunction, backslashes pile up exponentially (each layer has to double the number of slashes). See example of a backslash explosion and alternatives to avoid this below .
This kind of backslash explosion is known as Leaning toothpick syndrome , and can happen in many situations . Below is an explanation of all the entries in the comic .
The backslash explosion in the title text is about a bash command (which uses the backslash to escape arguments) invoking the grep utility which searches for text following a pattern specified by means of a regular expression (which also uses the backslash to escape special characters). This leads to 3 backslashes in a row in the command, which could easily become 7 backslashes in a row if the text being searched for also contains a backslash.
Even advanced users who completely understand the concept often have a hard time figuring out exactly how many backslashes are required in a given situation. It is hopelessly frustrating to carefully calculate exactly the number of backslashes and then noticing that there's a mistake so the whole thing doesn't work. At a point, it becomes easier to just keep throwing backslashes in until things work than trying to reason what the correct number is.
It's unclear whether the regular expression in the title text is valid or not. A long discussion about the validity of the expression has occurred here on this explanation's talk page . The fact that many editors of the site, often themselves extremely technically qualified, [ citation needed ] [ citation needed ] can't determine whether the expression is valid or not, adds a meta layer to the joke of the comic. This is an example of nerd sniping (oh, the irony\!\!\!\).
A reasonable example of a backslash explosion would be a PHP script on a web server which writes JavaScript code with a Regular Expression to be run on the client. If the JavaScript code has to test a string to see if it has a double-backslash, the Regular Expression to do so would be:
where the first two backslashes represent a single backslash and the second two also represent a single backslash, so this searches for two consecutive back slashes.
And the JavaScript would be:
where every two backslashes means just one backslashes in the string, so the 8 backslashes in JavaScript become 4 backslashes in the Regular Expression.
However, since this JavaScript code is to be written through a PHP script, the PHP code would be:
where:
So, the presented scenario has escalated from a simple test for \\ to no less than seventeen backslashes in a row without stepping out of the most common operations.
If we go a bit further and try to write a Java program that outputs our PHP script, we'd have:
Here, we have 35 backslashes in a row: the first 34 produce the 17 we need in our PHP script, and the last one is for escaping the quote character. (This comes closer to The true name of Ba'al, the Soul-Eater ).
Some programming languages provide alternative matching string literal delimiters to limit situations where escaping of delimiters is needed. Often, one can begin and end a string with either a single quote or a double quote. This allows one to write 'This is a "quoted" string' if double quote marks are intended in the string literal or "This is a 'quoted' string" if single quote marks are intended. Both kinds of delimiters can't be used in the same string literal, but if one needs to construct a string containing both kinds of quote marks one can often concatenate two string literals, each of which uses a different delimiter.
Another feature that seems to be popular in modern programming languages is to provide an alternative syntax for string delimiters designed specifically to limit leaning toothpick syndrome. For example, in Python, a string literal starting with r" is a "raw string" [1] in which no escape processing is done, with similar semantics for a string starting with @" in C#. This allows one to write r"C:\Users" in Python or @"C:\Users" in C# without the need to escape the backslash. This does not allow one to embed the terminating delimiter in the middle of the string and prevents the use of the backslash to encode the newline character as \n , but comes in handy when writing a string encoding of a regular expression in which the backslash is escaping one or more other punctuation characters or a shorthand character class (e.g., \s for a whitespace character). For example, when looking for an anchor tag in HTML, developers may encode the regular expression as <[Aa]\s[^>]*> . If they express this regular expression as a raw string literal, the code looks like r"<[Aa]\s[^>]*>" instead of "<[Aa]\\s[^>]*>" . The point here is that "leaning toothpick syndrome" is such a real problem that it has influenced programming language implementations.
[A list of the names of different numbers of backslashes. After each "item" there is a gray line to the text describing each item. As the text is aligned above each other, the lines becomes shorter as the sequence of backslashes becomes longer until there is just a line with the length of a single hyphen for the last item. There are 1 to 8 backslashes and then 11 plus "..." in the last entry.] \ ------------ Backslash \\ ----------- Real backslash \\\ ---------- Real real backslash \\\\ ---------- Actual backslash, for real this time \\\\\ --------- Elder backslash \\\\\\ -------- Backslash which escapes the screen and enters your brain \\\\\\\ ------- Backslash so real it transcends time and space \\\\\\\\ ------ Backslash to end all other text \\\\\\\\\\\... - The true name of Ba'al, the Soul-Eater
The title text when first published was
It was changed within a few days to
The original title text seems to be more relevant to the comic, but the revised title text seems to make more sense as a legitimate command line due to the way backslashes are interpreted in regular expressions. See the Discussion below for much more on the topic.
