Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby regexp handling of nbsp

In ruby 1.9.3 the regex engine doesn't treat nbsp's (\u00A0) as a space (\s). This is often a bummer for me.

So my question is, will this change in 2.0? If not, is there any way to monkey patch a solution?

like image 382
pguardiario Avatar asked Nov 08 '12 10:11

pguardiario


1 Answers

Use Unicode properties (you need to declare a matching source code encoding for this to work):

# encoding=utf-8 
if subject ~= /\p{Z}/
    # subject contains whitespace or other separators

or use POSIX character classes:

if subject ~= /[[:space:]]/

According to the docs, \s will only match [ \t\r\n\f] now and in the future.

like image 153
Tim Pietzcker Avatar answered Oct 22 '22 00:10

Tim Pietzcker