zero width token?

痴心易碎 提交于 2019-12-12 12:09:01

问题


I want to ask a very basic question about token,
while reading about regex,the book tag caret(^) as a zero width token, can you please tell me what actually it means by zero width?


回答1:


It means that it matches without consuming any characters. It is simply a positional assertion ("must be at the start of the line"). Another example is zero-width look-ahead and look-behind assertions. For instance, the Perl regex /abc(?=123)/ matches the sequence abc only if it is followed by the sequence 123, but it doesn't actually consume the 123.




回答2:


It's a zero width token because it is a token that matches the zero width string, i.e. the string containing zero characters. The number of characters in a string is sometimes called its width. It matches only the empty string if it occurs at the start of the string, or at the start of any line depending on the options.

Another example of a zero width token is \b which matches a word boundary.




回答3:


^ is just tell you a context and is not representing any physical character or characters.

^'s context is the beginning of a line.

Other examples are:

$ - end of line context

\b - word boundaries



来源:https://stackoverflow.com/questions/3275375/zero-width-token

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!