Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zero width token?

Tags:

regex

token

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?

like image 512
Tarun Avatar asked Jan 22 '23 18:01

Tarun


1 Answers

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.

like image 147
Marcelo Cantos Avatar answered Jan 31 '23 15:01

Marcelo Cantos