I've seen multiple solutions to remove non-ascii characters from a string using regex. I'd like to do the inverse, so removing ascii characters from a string so I am only left with the non-ascii ones.
Example:
without_ascii "a" #=> ""
I've seen multiple solutions to remove non-ascii characters from a string using regex. I'd like to do the inverse, so removing ascii characters from a string so I am only left with the non-ascii ones.
Example:
without_ascii "a" #=> ""
Well, just do the opposite of answers you found!
"a".gsub(/\p{ASCII}/, '') #=> ""
"a".delete("\u{0000}-\u{007F}") #=> #=> ""
Note that the question you linked was using \P
which means negation of \p
for String#gsub
. And ^a-z
which means delete all except characters from a
to z
for String#delete
.