ruby - Whitespaces not escaped by /\s/ -
I am working with some strings that behave in a weird way.
Some spaces are not recognized in Ruby in a regex / s by
"175 75 16C 101/99 R" .gsub (/ \ s / , 'X') = & gt; "175 x75 x 16 c x101 / 99 xR"
It is expected that every white spot is changed to 'X'
I have a UTF-8 On string but this is not working either I need a regedge that matches every type of white spot in my string and converts them to whitespace regularly.
Edit:
str.encode ('utf-8') Chars.each {| C | Puts c.ord} 49 55 53 160 32 55 53 160 160 32 49 54 67 160 32 49 48 49 47 57 57 160 160 160 32 82 [\ t \ r \ n \ f]
(only one If your pattern contains letters with other white space, such as non-breaking spaces, you \ s
to \ p { Z}
, which will look for Unicode separator character property and thus will match everyone.
Comments
Post a Comment