I've Just started with lex programmming. The first assignment was to seperate the vowels and consonants from a file. The rule for the vowel which I wrote was- [ aeiouAEIOU ] {return VOWEL};
For consonants, it would be tedious to write the code - [b-dB-D.....]
. Is there a way like {alphabets} - {unwanted chars}
?
Asked
Active
Viewed 123 times
0

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129
1 Answers
0
Yes, there is (in flex, not in other lex implementations):
[[:alpha:]]{-}[aeiouAEIOU]
You could also use a case-insensitive pattern:
(?i:[[:alpha:]]{-}[aeiou])
The {-}
operator only works with character classes. It won't work with macro definitions or multicharacter subpatterns. (These will produce a syntax error when flex tries to parse the pattern.)
For more information, see the flex manual chapter on patterns.

rici
- 234,347
- 28
- 237
- 341