0

I am trying to match an exact word for lexical analysis in Flex. Concretely, I am looking for the word class, and have tried this regex \bclass\b which works fine at rubular. I have already tried the example given here but for some reason Flex fails to emulate the output at rubular. Can you explain why? And how exactly to do it?

Community
  • 1
  • 1
user1343318
  • 2,093
  • 6
  • 32
  • 59

1 Answers1

1

Simply put, because flex is flex and www.rubular.com is "a Ruby regular expression editor" (quoting from home page, emphasis added).

Flex regular expression syntax is explained in the flex manual; if you read that, you will see that for flex interprets \b as in standard C; that is, as a backspace character.

It's important to understand how Flex works (for which it is useful to read an introductory guide, for example in the manual); in summary, it successively matches tokens, each one occurring immediately after the previous one. It should not be necessary to provide boundary assertions because the previous text will already have been matched up to the start of the word, and there should be an explicit token pattern which will match longer words which happen to start with the target word's letters. Take a look at the example in the Wikipedia article, for example.

rici
  • 234,347
  • 28
  • 237
  • 341
  • as a side note as well on this, you'll want to make sure your most specific patterns come first, and then become more general, as it will try to match as much as it can of a given token pattern. – JPC Jul 01 '14 at 20:58