Last Updated: February 25, 2016
·
378
· steimntz

Regex to match unprintable characters

If you want to get unprintable characters you can use the following simple code:

Expression:

/[^\p{Print}]/

You can see how it works on the following Ruby example:

Code:

omg = "OMG!\nHi!  \n\r\t"
omg.gsub(/[^\p{Print}]/, "*")

The result is going to be like that:

"OMG!*Hi!  ***"