我很困惑为什么在以下示例#2
中不起作用并且#3
起作用。
#1. get `o` if immediately preceded by J
"Jones Bond".scan(/(?<=J)o/) #=> o
#2. get `o` if preceded by J anywhere. Since `J` occurs once I am using `+`
"James Bond".scan(/(?<=J)+o/) #=> [] empty
#3. get `o` if preceded by J anywhere zero or more times by using `*`
"James Bond".scan(/(?<=J)*o/) #=> o
我翻译lookbehind
asleft-to-right
和lookahead
asright-to-left
很容易记住。这是对的吗?