regex - How to recognize a string literal for a scanner in lex? -


OK, I'm trying to find a regular expression in Lex that identifies the string as a string in an input string Will take like. In printf ("stackoverflow"), "stackoverflow" should be recognized as a string, verbatim I am trying the following:

  "[.] + "["] [.] + ["] \" [.] + \ "[\"] [.] + [\ "]" "" [.] + "" ""   < P> None of these is working. Each time the name "alone" is recognized, what should I do? Thanks in advance ...   

Simple, try:

  \ ". * \" Printf ("STRING [% s]", yytext); \ '. * \ 'Printf ("STRING [% s]", yytext);   

While compiling and running, a quick test shows that

  "Hello world!" STRING ["Hello world!"] 'Hello world!' '[Hello world!'] 'John's cat' STRING ['John' cat ']' Mary said, 'hello!' 'STRING' said Mary, "Hello!" '' Bye! '' Frank said, "these words are" in which "there is a string that these words are in STRING [" in which "] a string   

Cheers, Chris < / P>

Comments