How do I specify a valid character property using Oniguruma regexes?
I'm using the oniguruma gem to get unicode-aware regexes in ruby 1.8. According to the syntax documentation, I should be able to use \p{M}
or \p{Mark}
to match code points with the Mark property.
However, when I do the following
ORegexp.new '\p{M}',
:options => OPTION_MULTILINE | OPTION_SINGLELINE | OPTION_IGNORECASE | OPTION_EXTEND,
:syntax => SYNTAX_JAVA, # so we can use character properties
:encoding => ENCODING_UTF8
I get ArgumentError: Oniguruma Error: invalid character property name {M}
. I get the same error if I use {Mark}
, or if I use one of the other syntaxes that support \p
.
What am I doing wrong? How do I specify a valid character property using Oniguruma regexes?
UPDATE - If I use one of the UTF16 encodings, the regex compiles; but since my strings are in UTF8 that doesn't help. So my question becomes:开发者_StackOverflow中文版 how do I specify a valid character property using UTF-8 Oniguruma regexes?
Try using
/\p{Mark}
I was reading on an old Ruby blog that using the forward slash would "try to find the value as encoding in the string"
http://www.ruby-forum.com/topic/154384
精彩评论