You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Examples shown below tested with Ruby 2.7.1p83. In first example, the string to match after \K can be empty sometimes and in second example, it is always empty. When the match turns out to be empty, \K is failing to match the immediate next match.
# example 1
>> ',cat,tiger,dog'.gsub(/(?<=\A|,)[^,]*+/,'{\0}')=>"{},{cat},{tiger},{dog}"# note that 'dog' is matched because previous match wasn't empty# but 'cat' fails to match, possibly because previous match was empty
>> ',cat,tiger,dog'.gsub(/(?:\A|,)\K[^,]*+/,'{\0}')=>"{},cat,{tiger},{dog}"# example 2
>> 'abcd 123456'.gsub(/(?<=\w)/,':')=>"a:b:c:d: 1:2:3:4:5:6:"
>> 'abcd 123456'.gsub(/\w/,'\0:')=>"a:b:c:d: 1:2:3:4:5:6:"# every second word character is failing to be matched
>> 'abcd 123456'.gsub(/\w\K/,':')=>"a:bc:d 1:23:45:6"
This is different from the behavior seen with perl, vim (using \zs) and third-party regex module in python.
Examples shown below tested with Ruby 2.7.1p83. In first example, the string to match after
\K
can be empty sometimes and in second example, it is always empty. When the match turns out to be empty,\K
is failing to match the immediate next match.This is different from the behavior seen with
perl
,vim
(using\zs
) and third-party regex module inpython
.The text was updated successfully, but these errors were encountered: