Closed mingodad closed 1 year ago
Yes, the second form you have in flex there is the correct one.
The thing is if both uses the same strategy (dfa) why one works and the other don't ? I mean regular expressions work but flex doesn't with both regexes.
With this \"(?:\\.|[^\"\n\r])*\"|'(?:\\.|[^'\n\r])*'
and this \"(?:\\.|[^\"\n\r\\])*\"|'(?:\\.|[^'\n\r\\])*'
regex on https://regex101.com/ the following languages recognize all strings: Java8
, Golang
, Python
, Javascript
and PCRE
.
Those other implementations aren't using DFA/leftmost longest.
There are actually multiple regex flavours, but let's keep things simple.
See also discussion here https://github.com/BenHanson/lexertl14/issues/13
Testing this
"(?:\\.|[^"\n\r])*"|'(?:\\.|[^'\n\r])*'
on https://regex101.com/ gives this:Testing this
"(?:\\.|[^"\\\n\r])*"|'(?:\\.|[^'\\\n\r])*'
on https://regex101.com/ gives this:Test string:
But with flex it gives this:
Output:
Output: