How AI is applied across API Evangelist and APIs.io. Read my AI disclosure →
API Evangelist API Evangelist
Discovery
Learnings
Guidance
Toolbox
Alignment
API Evangelist LLC

Why to avoid \x in regular expressions

calendar_today June 26, 2022 person domain r

Using \x in string literals is almost always a bad idea, but using it in regular expressions is particularly dangerous. Consider this “don’t do” example in R 4.2.1 or earlier: text <- “Hello\u00a0R” gsub(“\xa0”, “”, text) a0 is the code point of the Unicode “NO-BREAK SPACE” and the example runs in UTF-8 locale. The intention is to remove the space; a slightly more complicated variant has been discussed on the R-devel mailing list about half a year ago.

open_in_new Read original post