Weird behavior with regex and \b escape character

Would you expect the following two functions calls to give the same result? What is happening here?

iex(24)> String.contains?("a", "\b")
false
iex(25)> String.match?("a", ~r/\b/) 
true

In a regular expression, \b is an assertion that matches at a word boundary.

If you intend to match a backspace character, you could use a character class: ~r/[\b]/

2 Likes

Thank you :-)!