Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Unicode字符会阻止[[:punct:]字符类匹配"+&引用;在Ruby 2.4中的后续regexp匹配中?_Ruby_Regex_Unicode - Fatal编程技术网

为什么Unicode字符会阻止[[:punct:]字符类匹配"+&引用;在Ruby 2.4中的后续regexp匹配中?

为什么Unicode字符会阻止[[:punct:]字符类匹配"+&引用;在Ruby 2.4中的后续regexp匹配中?,ruby,regex,unicode,Ruby,Regex,Unicode,我在Ruby中遇到了一个奇怪的bug。在Ruby 2.4.2中,与包含Unicode字符的字符串进行匹配会导致后续匹配失败 下面是我尝试隔离该bug的步骤: puts RUBY_VERSION ["0.", "0+", "é", "0.", "0+"].each do |phrase| p phrase[/[[:digit:]][[:punct:]]/] end 以下是各种Ruby版本的输出: 2.3.5 "0." nil nil "0." nil 2.4.2 "0." "0+" nil

我在Ruby中遇到了一个奇怪的bug。在Ruby 2.4.2中,与包含Unicode字符的字符串进行匹配会导致后续匹配失败

下面是我尝试隔离该bug的步骤:

puts RUBY_VERSION
["0.", "0+", "é", "0.", "0+"].each do |phrase|
  p phrase[/[[:digit:]][[:punct:]]/]
end
以下是各种Ruby版本的输出:

2.3.5
"0."
nil
nil
"0."
nil

2.4.2
"0."
"0+"
nil
"0."
nil

2.5.0
"0."
"0+"
nil
"0."
"0+"
在2.3.5中,
0+
被完全忽略,显然是因为
+
不被认为是标点符号。在2.5.0中,
0.
0+
都是匹配的


但在2.4.2中,这种行为令人困惑:为什么对包含Unicode字符的字符串进行匹配会干扰后续的正则表达式匹配?大概这是一个bug,但我找不到关于它是如何引起的或如何解决它的任何信息。

BTW,这个例子可以缩短为
p%w[++].grep(/[[:putt:]]/)
,它返回
[“+”]
而不是2.4.2中的
[“+”,“+”]
,非常有趣的是,
%w[+++]
似乎工作正常(在2.4.1中),而
%w[+µ+]。每个{s | ps[/[:punct:]/]}
都没有。相关:我创建了一个错误报告: