I am working on a flex
lexer for a language and suddenly discovered a problem that had never bothered me before: integer number recognition. I use a simple RE with the trailing context (as suggested in https://stackoverflow.com/a/22413732/4492932):
%%
[[:digit:]]+/[^[:alpha:]] { printf("-%s-\n", yytext);}
. {}
\n {}
%%
The program works as designed when the input string consists only of digits. When the supposed number has an illegal letter "tail," the last digit of the number is not included in yytext
:
1234
-1234-
1234abcd
-123-
Why is "4" not matched?