Skip to main content
More explanation
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

Pip, 6 bytes

RP``.q

Try it online!

Explanation

Um... well, this is interesting.

It just so happens that Pip's Pattern type (used for regex) is delimited with backticks. And that backticks can be escaped within a Pattern using backslashes.

... And furthermore, that the code for generating the Pip repr of a Pattern is apparently incorrect, because it should escape the backslashes too, but in fact it only escapes the backticks. Which is exactly the behavior this question asks for.

"It's not a bug, it's a feature"? ¯\_(ツ)_/¯

     q  Read a line of stdin
  ``.   Cast it to a Pattern by concatenating an empty Pattern to it
RP      Get the repr

Okay, I've looked at this again and I think it's not actually a bug. The reason why I thought it was a bug was because some of the inputs are not possible to enter as Pattern literals. Since they are "impossible" Patterns, it makes sense that their reprs are not correctly formed representations of Pattern literals.

Input  Repr    Comment
`      `\``    Properly formed: backtick is escaped with a backslash
\\`    `\\\``  Properly formed: backslash is also escaped with a backslash
\`     `\\``   Improperly formed: first backtick is not escaped

You can't enter a regex for \` in Pip because \` is not a properly formed regex. (If you want a regex that matches the string \`, you should use \\`, which is entered as `\\\``. Clear as mud? Great.)

In summary, inputs with only even-length runs of backslashes output well-formed reprs, but if there is an odd run of backslashes, all bets are off.

Pip, 6 bytes

RP``.q

Try it online!

Explanation

Um... well, this is interesting.

It just so happens that Pip's Pattern type (used for regex) is delimited with backticks. And that backticks can be escaped within a Pattern using backslashes.

... And furthermore, that the code for generating the Pip repr of a Pattern is incorrect, because it should escape the backslashes too, but in fact it only escapes the backticks. Which is exactly the behavior this question asks for.

"It's not a bug, it's a feature"? ¯\_(ツ)_/¯

     q  Read a line of stdin
  ``.   Cast it to a Pattern by concatenating an empty Pattern to it
RP      Get the repr

Pip, 6 bytes

RP``.q

Try it online!

Explanation

Um... well, this is interesting.

It just so happens that Pip's Pattern type (used for regex) is delimited with backticks. And that backticks can be escaped within a Pattern using backslashes.

... And furthermore, that the code for generating the Pip repr of a Pattern is apparently incorrect, because it should escape the backslashes too, but in fact it only escapes the backticks. Which is exactly the behavior this question asks for.

"It's not a bug, it's a feature"? ¯\_(ツ)_/¯

     q  Read a line of stdin
  ``.   Cast it to a Pattern by concatenating an empty Pattern to it
RP      Get the repr

Okay, I've looked at this again and I think it's not actually a bug. The reason why I thought it was a bug was because some of the inputs are not possible to enter as Pattern literals. Since they are "impossible" Patterns, it makes sense that their reprs are not correctly formed representations of Pattern literals.

Input  Repr    Comment
`      `\``    Properly formed: backtick is escaped with a backslash
\\`    `\\\``  Properly formed: backslash is also escaped with a backslash
\`     `\\``   Improperly formed: first backtick is not escaped

You can't enter a regex for \` in Pip because \` is not a properly formed regex. (If you want a regex that matches the string \`, you should use \\`, which is entered as `\\\``. Clear as mud? Great.)

In summary, inputs with only even-length runs of backslashes output well-formed reprs, but if there is an odd run of backslashes, all bets are off.

added 33 characters in body
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

Pip, 6 bytes

RP``.q

Try it online!Try it online!

Explanation

Um... well, this is interesting.

It just so happens that Pip's Pattern type (used for regex) is delimited with backticks. And that backticks can be escaped within a Pattern using backslashes.

... And furthermore, that the code for generating the Pip repr of a Pattern is incorrectincorrect, because it should escape the backslashes too, but in fact it only escapes the backticks. Which is exactly the behavior this question asks for.

"It's not a bug, it's a feature"? ¯\_(ツ)_/¯

     q  Read a line of stdin
  ``.   Cast it to a Pattern by concatenating an empty Pattern to it
RP      Get the repr

Pip, 6 bytes

RP``.q

Try it online!

Explanation

Um... well, this is interesting.

It just so happens that Pip's Pattern type (used for regex) is delimited with backticks. And that backticks can be escaped within a Pattern using backslashes.

... And furthermore, that the code for generating the Pip repr of a Pattern is incorrect, because it should escape the backslashes too, but in fact it only escapes the backticks. Which is exactly the behavior this question asks for.

"It's not a bug, it's a feature"? ¯\_(ツ)_/¯

     q  Read a line of stdin
  ``.   Cast it to a Pattern by concatenating an empty Pattern to it
RP      Get the repr

Pip, 6 bytes

RP``.q

Try it online!

Explanation

Um... well, this is interesting.

It just so happens that Pip's Pattern type (used for regex) is delimited with backticks. And that backticks can be escaped within a Pattern using backslashes.

... And furthermore, that the code for generating the Pip repr of a Pattern is incorrect, because it should escape the backslashes too, but in fact it only escapes the backticks. Which is exactly the behavior this question asks for.

"It's not a bug, it's a feature"? ¯\_(ツ)_/¯

     q  Read a line of stdin
  ``.   Cast it to a Pattern by concatenating an empty Pattern to it
RP      Get the repr
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

Pip, 6 bytes

RP``.q

Try it online!

Explanation

Um... well, this is interesting.

It just so happens that Pip's Pattern type (used for regex) is delimited with backticks. And that backticks can be escaped within a Pattern using backslashes.

... And furthermore, that the code for generating the Pip repr of a Pattern is incorrect, because it should escape the backslashes too, but in fact it only escapes the backticks. Which is exactly the behavior this question asks for.

"It's not a bug, it's a feature"? ¯\_(ツ)_/¯

     q  Read a line of stdin
  ``.   Cast it to a Pattern by concatenating an empty Pattern to it
RP      Get the repr