Zero-width marker?

I want to ask a very simple question about a token,
while reading about regex, book caret (^) tag as a zero-width marker, can you tell me what zero-width really means?

+4
source share
3 answers

This means that it matches without using any characters. This is just a positional statement ("must be at the beginning of the line"). Another example is zero-width statements and expectations. For example, the regular expression Perl /abc(?=123)/ matches the sequence abc only if it is followed by the sequence 123 , but in fact it does not consume 123 .

+6
source

This is a token with zero width, because it is a token that corresponds to a zero-width string, i.e. a string containing null characters. The number of characters in a string is sometimes called its width. It matches only an empty line if it occurs at the beginning of a line or at the beginning of any line, depending on the parameters.

Another example of a zero-width marker is \b , which matches the word boundary.

+3
source

^ just tells you the context and does not represent any physical characters or characters.

^ context is the beginning of a line.

Other examples:

$ - end of line context

\ b - word boundaries

0
source

Source: https://habr.com/ru/post/1316072/


All Articles