Sitemap

Except it’s fun: Escape Characters in 3 minutes

3 min readFeb 3, 2024

--

Ahh the escape character — my favourite! All you have to do is remember:

The escape character giveth, and the escape character taketh away…

What is it?

A character like any other on your keyboard, but with a special and important mission… Most often — it’s represented by the \ character.

What does it do?

It alters the behaviour of the character immediately after it!

Alters.. how?

OK — story time:

The escape character ( \ ) precedes any other character. If the character it precedes is a metacharacter (or, as I like to say, “has superpowers”!) — it turns it back into a normal character.

Press enter or click to view image in full size
Images are AI generated with Bing Image Creator.

Many languages designated metacharacters to perform special commands. For example, * in Word will create bullet points, whilst + in regular expressions is a “1 or more” quantifier. Well, no more! Pair them with the \ and you strip them off their powers — easy peasy! (Examples at the end)

Right! And if it doesn’t have superpowers?

Not so fast! Some of the “normal” characters are really superheroes in disguise! In that case:

The escape character may “activate” the superpowers of a seemingly standard character as well (or as I like to say, remove its disguise!). Not all “normal” characters are latent heroes though, some are just themselves. (and that’s more than enough ❤)

Press enter or click to view image in full size
Images are AI generated with Bing Image Creator.

For example, the letter ‘d’ is a seemingly standard, hard-working citizen amongst the characters. Pair it with \ → \d and behold! Many programming languages recognizing regular expressions will quickly tell you that’s a shortcut for “digits” or all characters from 0 to 9.

Get Alex Caian’s stories in your inbox

Join Medium for free to get updates from this writer.

And that’s all! In short, the escape character:

If it can* : It will swap the metacharacter back to a normal one and vice-versa.

\* Here being that some normal characters have no meta version. :)

Examples

  1. Let’s type some reactions on Discord:
Press enter or click to view image in full size

Here’s the results!

2. What about “normal” to “special”? Let’s check Python!

Press enter or click to view image in full size

This was escape characters in 3 minutes! What should we learn next? Thank you for reading. :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I’m open to answering any other questions in private — just drop me a message on LinkedIn or Email :)

Find me on: Github || LinkedIn or via email at axl_acc@yahoo.ro

--

--

Alex Caian
Alex Caian

Written by Alex Caian

I only write blogs when I believe people can extract some value from them. If my experience helped you in some way, that's my time well spent creating a story.