\B
我刚刚对and有了一些概念\b
。并且accordinlgy 尝试了一个代码(取自互联网)但无法理解 - 这些输出是如何生成的regexp Anchors
。因此,请任何人帮助我理解它们之间的区别,\B
并\b
在内部说明它们pattern matching
在 Ruby 中的处理方式?
Interactive ruby ready.
> str = "Hit him on the head\n" +
"Hit him on the head with a 2×4\n"
=> "Hit him on the head
Hit him on the head with a 2??4
"
> str.scan(/\w+\B/)
=> ["Hi", "hi", "o", "th", "hea", "Hi", "hi", "o", "th", "hea", "wit"]
> str.scan(/\w+\b/)
=> ["Hit", "him", "on", "the", "head", "Hit", "him", "on", "the", "head", "with", "a", "2", "4"]
>
谢谢,