Re: [Flex-help] A problem with token '/' character (forward slash)
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Aaron J. <ja...@ms...> - 2008-06-10 03:17:35
|
On Jun 9, 2008, at 5:01 PM, Praseed V Gopal wrote: > Hi All, > > I have a flex macro definition > filepathstr [0-9a-zA-Z_\-]{1,255} > which support file names like "nest.c" & "foo_1.c" > > Now I want to add support for file names like "/home/sweet/den.c" > Basically accept token '/' character (forward slash) in the > filepathstr. > I tried different combinations, escape sequence '\' and double > quotes like > 1.filepathstr [0-9a-zA-Z_\-\/]{1,255} > 2. filepathstr [0-9a-zA-Z_\-"/"]{1,255} > and many more. > > I'm not so familiar with flex, so not sure how to fix this & get it > working with forward slash is considered as just "/" & not 'trailing > context'. > > Any answers or suggestions are welcome. As far as I know, the ``/'' character does not need to be escaped in a class. The character ``-'' does not need to be escaped, if it is the first or last character in the class, and you don't seem to be matching the ``.'' character. BTW, your regular expression is not very precise. I would use something like (not tested) filepathstr ([/])?([0-9a-zA-Z_\.-]+[/])?[0-9a-zA-Z_\.-]+ filepathstr [0-9a-zA-Z_/-]{1,255} would match 1,255 /s in a row. |