07-26-2023, 04:56 PM
I look here [ANSI C grammar][1] .
[1]:
This page includes a lot of regular expressions in Lex/Flex for ANSI C.
Having a problem in understanding regular expression for string literals.
They have mentioned regular expression as `\"(\\.|[^\\"])*\"`
As I can understand `\"` this is used for double quotes, `\\` is for escape character, `.` is for any character except `escape character` and `*` is for zero or more times.
`[^\\"]` implies characters except `\` , `"` .
So, in my opinion, regular expression should be `\"(\\.)*\"`.
Can you give some strings where above regular expression will fail?
or
Why they have used `[^\\"]`?
[1]:
[To see links please register here]
This page includes a lot of regular expressions in Lex/Flex for ANSI C.
Having a problem in understanding regular expression for string literals.
They have mentioned regular expression as `\"(\\.|[^\\"])*\"`
As I can understand `\"` this is used for double quotes, `\\` is for escape character, `.` is for any character except `escape character` and `*` is for zero or more times.
`[^\\"]` implies characters except `\` , `"` .
So, in my opinion, regular expression should be `\"(\\.)*\"`.
Can you give some strings where above regular expression will fail?
or
Why they have used `[^\\"]`?