2 ms·
> The regex [ -~] lets you match those characters, whereas [^ -~] negates that and matches anything that's not a printable ASCII character Oh dear, I think I f
by sundarurfriend 9y ago
> The regex [ -~] lets you match those characters, whereas [^ -~] negates that and matches anything that's not a printable ASCII character
Oh dear, I think I finally understand that mysterious phenomenon in some websites where, text I write in my native language gets saved and displayed as empty text, but writing in English works. I've come across this a few times over the years, in random forgotten corners of the Internet. It could well be that this regex got written down somewhere as good security practice, and some developers out there copied it into the code without thinking about whether the ASCII restriction is applicable.
- cosmie 9y agoIt's probably a more mundane issue related to either older versions of HTML (which did not support UTF8[1]), or issues with an older database that stored things as latin1 or ASCII by default, or issues with an older programming language that doesn't seamlessly support non-latin1 or non-ascii characters without deliberately doing so (like Python 2). That said, I do agree it's not something that should be used without thought. I mentioned that my usage generally involves knowledge that the data set has no valid reason to contain higher code points, and usually involves usage of Unidecode[2] to convert higher code points into ASCII equivalents (which in many cases strips out contextual knowledge, but is sometimes an acceptable trade off for stability and predictability of the data sent downstream). [1] https://www.w3schools.com/html/html_charset.asp https://www.w3schools.com/html/html_charset.asp [2] https://pypi.python.org/pypi/Unidecode https://pypi.python.org/pypi/Unidecode