Following method failed because \k<INDEX>
is not valid for Crystal, but it works with Ruby.
def first_non_repeating_char_1(str)
# Use a Regex negative look-ahead assertion to find the position
# where the next char is different with current char, do it twice.
idx = /(.)(?!a)(.)(?!b)/i =~ str
str[idx + 1]
end
str = 'aaabbbccrdddeeefdddccceeeaaakfffl'
assert_equal 'r', first_non_repeating_char_1(str)
19 | idx = /(.)(?!\k<-1>)(.)(?!\k<-1>)/i =~ str
^
Error: invalid regex: subpattern name expected at 9
Why Crystal not support it? any alternative?