(I'm escaping all my quotes, which may make it difficult to read)
I need to match a string that begins and ends with the same character in flex...I know the long hand way (RE being - \"a[^(a\")]a\" | \"b[^(b\")b\" | etc...), but I'm positive this isn't what I'm required to do (midterm tomorrow!);
I need to do this in flex, but if you can think of a short regex for it, I may be able to convert it to flex notation.
What I was thinking of was something along the lines of -
%%
int firstChar;
%x string;
%%
\"[A-Za-z] { firstChar = yytext+1; /* to get first character,
for people unfamiliar
with c pointers */
BEGIN(string);}
<string>[^((firstChar)\")] {}
<string>[(firstChar)\"] { BEGIN(INITIAL); }
(new to flex, may be incorrect notation)
But this bugs me in a few ways, first, having that variable makes this not a regular language; second, I don't know if you can even use a variable to in a pattern match; and third, I don't know how NOT to match it, if it's just a normal string. And third, I don't know how to return everything that's been matched while in 'string'
Thanks for your help!