mruoss
Hey, does anybody know if it is possible to escape escape characters like \r or \u2003? Given a string containing such characters, I’d like to turn them into an escaped form as follows:
iex> Magic.escape("\r\u2003")
"\\r\\u2003"
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
The only thing that I am aware of after 5 minutes of searching is Regex.escape/1.
And it only covers part of these: Escape characters.
adamu
Do you mean at compile-time?
You cannot do it at runtime, because once you have a string, you cannot identify how that string was produced. For example:
Given the string
" ", there’s no way to tell if the source code entered the value directly, used the escape character, or or constructed the string some other way.mruoss
Hi @adamu
I don’t mean to restore it the way it was created. I just need to restore it to one of the escape char variants.
For example I would want this:
@dimitarvp It is not exactly what I am looking for as it does a bit more.
adamu
Including for all spaces, newlines, unicode characters, and random bytes?
mruoss
Excluding newlines, tabs and spaces. But others like \r, \0, \uNNNN…
The more I think about it, the more I get the feeling that it is not possible…
adamu
\r is carriage return, you probably want to skip that too. \uNNNN is all Unicode characters, so literally everything that’s valid Unicode would be converted to that.
I think the problem is that what you are asking for doesn’t make sense.
What are you trying to do?
Eiji
All you need to do is to define a list of characters you want to escape and the rest is a simple
reduce:mruoss
Thank you all for the input and the sparring. @Eiji I guess I was hoping for some well-defined distinction / function to tell “printable” from other unicode chars. But I learned that what needs to be escaped depends very much on the use case. Looking at Jason, there is the
:escapeoption which can be one of 4 possible values, each one escaping more or fewer chars.@adamu Yes, that too, probably!
Inspired by Jason I ended up with something like the following which works for my case for now (probably needs refinement):
Eiji
Enum.reject(0x00..0x1F, & &1 in '\n\t')https://github.com/rrrene/elixir-style-guide
adamu
What are you trying to do with that information?