1

You may think that it is a duplicate question of this.

And actually it is a similar question of that question. Then why am I asking it again?

Because, the accepted answer of that question does not work. The answer might be fulfilled the OP's requirement, but that is not a general answer.

The other reason is, it should work in flex.

I need a regular expression which would accept only those strings which contain vowels in any order.

It may have some other letters, but all vowels must occur at least once.

Let's see some examples:

String                         Accepted or Not
----------------------         ---------------
abceioussa                     Accepted
aeiou                          Accepted
uioae                          Accepted
odsidsfusjldkfuuuu             Not Accepted
bcesdddsoaiaaau                Accepted
aaaaaaaaeeeeeeeooooiu          Accepted
aasssssaeeeeeeeoeoooi          Not Accepted

Edit:

Remember, It should work in flex.

Edit 2:

Task:

Pattern                                                         Action
-------------------------------------------------------------   --------------------
Blank Space, tab space                                          Do nothing
New line                                                        Count number of line
Any word contains all five vowels at least once                 Print VOWELS
Any word ends with s or es                                      Print PLURAL
Any word ends with ly                                           Print ADVERB
Any word ends with ing                                          Print CONTINUOUS
is/do/go/be/are/was/were/did                                    Print VERB
a/an/the                                                        Print ARTICLE
Any word starts with uppercase letter and none of the above     Print NOUN
Anything else                                                   Print NOT_RECOGNIZED

Scanner4.l:

Look have to fill expression for regular definition vowel only.

%{
    /* comments */
    #define ECHO fwrite(yytext, yyleng,1,yyout);
    int yylineno = 0, ii;
%}
letter [a-zA-Z]
uppercase [A-Z]
digit [0-9]
digits [0-9]+
punc [-=\+\\_\.,\.\|\~\!\$\%\^\&\(\\;\'\"\?\{\}\[\]\)\/\#\*@]
anything ({letter}|{digit})
spacetab [\t ]+
endmark [\n\t ]
dot [\.]
hp [\-]
verb (is|do|go|be|are|was|were|did)
article (a|an|the)
normal ({anything}|{punc})
vowel //here you have to write the expression
%option noyywrap
%%
{spacetab}|{punc}   { 
                        fprintf(yyout,"%s", yytext);
                        printf(":%s:%d ECHO\n",yytext,yylineno);
                        /* do nothing */
                    }
\n  {
        yylineno++; 
        ECHO; 
        printf(":%s:%d no echo\n",yytext,yylineno);
    }
{vowel}{endmark}    {
                        fprintf(yyout," VOWELS ");
                        fprintf(yyout,"%c", yytext[yyleng-1]);
                        if(yytext[yyleng-1]=='\n') yylineno++;
                        printf(":%s:%d vowels\n",yytext,yylineno);
                    }
{verb}{endmark}     {
                        fprintf(yyout," VERB ");
                        fprintf(yyout,"%c", yytext[yyleng-1]);
                        if(yytext[yyleng-1]=='\n') yylineno++;
                        printf(":%s:%d verb\n",yytext,yylineno);
                    }
{article}{endmark}  {
                        fprintf(yyout," ARTICLE ");
                        fprintf(yyout,"%c", yytext[yyleng-1]);
                        if(yytext[yyleng-1]=='\n') yylineno++;
                        printf(":%s:%d article\n",yytext,yylineno);
                    }
{letter}*(s|es){endmark}    {
                            fprintf(yyout," PLURAL ");
                            fprintf(yyout,"%c", yytext[yyleng-1]);
                            if(yytext[yyleng-1]=='\n') yylineno++;
                            printf(":%s:%d plural\n",yytext,yylineno);
                        }
{letter}*(ly){endmark}  {
                            fprintf(yyout," ADVERB ");
                            fprintf(yyout,"%c", yytext[yyleng-1]);
                            if(yytext[yyleng-1]=='\n') yylineno++;
                            printf(":%s:%d adverb\n",yytext,yylineno);
                        }
{letter}*(ing){endmark}     {
                            fprintf(yyout," CONTINUOUS ");
                            fprintf(yyout,"%c", yytext[yyleng-1]);
                            if(yytext[yyleng-1]=='\n') yylineno++;
                            printf(":%s:%d continuous\n",yytext,yylineno);
                        }
{uppercase}{letter}*{endmark}   {
                        fprintf(yyout," NOUN ");
                        fprintf(yyout,"%c", yytext[yyleng-1]);
                        if(yytext[yyleng-1]=='\n') yylineno++;
                        printf(":%s:%d noun\n",yytext,yylineno);
                    }

{normal}+{endmark}  { 
                        fprintf(yyout," NOT_RECOGNIZED%c", yytext[yyleng-1]);
                        if(yytext[yyleng-1]=='\n') yylineno++;
                        printf(":%s:%d as it is\n",yytext,yylineno);
                    }
%%
int main(){
    yyin = fopen("Input4.txt","r");
    yyout = fopen("Output4.txt","w");
    yylex();
    fprintf(yyout, "# of lines = %d\n", yylineno);
    fclose(yyin);
    fclose(yyout);
    return 0;
}

Input4.txt:

aasdfeasdfiasoasdfuasd aeiogedaeido aeiou oeiua aeeeee aeiouuu
speaiously Addoiuea aaaaaaa ing ly

Expected Output4.txt:

VOWELS  NOT_RECOGNIZED  VOWELS  VOWELS  NOT_RECOGNIZED  VOWELS
     VOWELS   VOWELS   NOT_RECOGNIZED  CONTINUOUS  ly
# of lines = 1

I compile it by the following commands:

flex Scanner4.l
mingw32-gcc -c lex.yy.c -o Scanner4.yy.o
mingw32-g++ -o Scanner4.yy.exe Scanner4.yy.o
Scanner4.yy
Community
  • 1
  • 1
Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
  • 1
    Possible duplicate of [How can I match a word containing every vowel at least once?](http://stackoverflow.com/questions/10324115/how-can-i-match-a-word-containing-every-vowel-at-least-once) – Kristján Nov 03 '15 at 15:17
  • The second answer in that question should work fine. – Shlomo Nov 03 '15 at 15:19
  • 1
    How come `abceioussa ` can be accepted if it has no `y`? `y` is a vowel, too, in some contexts. You exclude `y`, that is why "it does not work" for you. Here is a [regex without `y`](https://regex101.com/r/qJ4rE6/1): `(?i)^(?=.*a)(?=.*e)(?=.*i)(?=.*o)(?=.*u)`. – Wiktor Stribiżew Nov 03 '15 at 15:20
  • @Stribizhev But in my context it is not a vowel – Enamul Hassan Nov 03 '15 at 15:22
  • Too Funny Man! @Kristján – Enamul Hassan Nov 03 '15 at 15:22
  • no, it is not @Shlomo – Enamul Hassan Nov 03 '15 at 15:23
  • If you work with Flex, it means you are using JavaScript flavor. Use `^(?=[\s\S]*[aA])(?=[\s\S]*[eE])(?=[\s\S]*[iI])(?=[\s\S]*[Oo])(?=[\s\S]*[Uu])` to just check if all the 5 vowels are present in a string in any order. Note you might need to double the backslashes for this pattern to work (if you use `new RegExp`). Please post the code you have. – Wiktor Stribiżew Nov 03 '15 at 15:31
  • Could you clarify whether you're working with flex, the fast lexical analyzer, or Apache Flex, the Actionscript framework? – Brian Nov 03 '15 at 16:02
  • fast lexical analyzer @Brian – Enamul Hassan Nov 03 '15 at 16:42
  • Ah, this is mis-tagged. "flex-lexer" is the appropriate tag to use in that case. – Brian Nov 03 '15 at 17:03
  • then why the tag `flex` actually used for? Sorry, I am not experienced in this sector. @Brian – Enamul Hassan Nov 03 '15 at 17:06
  • From the [tag description](http://stackoverflow.com/tags/flex/info), `flex` refers to Apache Flex. – Brian Nov 03 '15 at 17:23
  • @stribizhev Is correct, if you remove the `y` portion of the [accepted answer](http://stackoverflow.com/a/10324746/2502532) in the [duplicate](http://stackoverflow.com/questions/10324115/how-can-i-match-a-word-containing-every-vowel-at-least-once), it will work for you. Here is a quick demo in JS which helps to illustrate it: https://jsfiddle.net/gfullam/m11zvpgz/ – gfullam Nov 03 '15 at 20:28
  • but it is not compatible with `flex`. @gfullam – Enamul Hassan Nov 04 '15 at 10:13
  • I'm surprised by that. It appears to be vanilla Reg Ex with no flavor specific additives. – gfullam Nov 04 '15 at 12:12
  • I didn't realize that flex-lexer syntax doesn't support positive lookahead, which most of these solutions rely on. You may be able to achieve what you want with the trailing context pattern, but it has limitations which may be tricky or impossible to overcome for this scenario. You may be interested in [the answer](http://stackoverflow.com/a/15561300/2502532) to [*Matching trailing context in flex*](http://stackoverflow.com/questions/15558684/matching-trailing-context-in-flex) which describes the use of trailing context in name definitions. – gfullam Nov 04 '15 at 15:20

4 Answers4

2

This positive lookahead based regex should work for you:

\b(?=[[:alpha:]]*[Aa])(?=[[:alpha:]]*[Ee])(?=[[:alpha:]]*[Ii])(?=[[:alpha:]]*[Oo])(?=[[:alpha:]]*[Uu])[[:alpha:]]+\b

RegEx Demo

(?=\w*a) enforces presence of a in the word and so or other lookaheads enforcing all vowels i.e. a,e,i,o,u.

Community
  • 1
  • 1
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    Hmm your question didn't mention `flex` earlier. Does `flex` support lookahead and recognizes `\w`? – anubhava Nov 03 '15 at 15:29
  • sorry, I forgot it to tell first. @anubhava – Enamul Hassan Nov 03 '15 at 16:47
  • 2
    If you're talking about Adobe Flex, your first three regexes work fine at [this site](http://ryanswanson.com/regexp/), but the current one with the POSIX character classes (`[[:alpha:]]` etc.) doesn't. (As expected, it being an ECMAScript implementation.) If you mean the lexer/scanner generator, it doesn't support lookaheads. – Alan Moore Nov 03 '15 at 16:58
  • @anubhava sorry, this does not serve my purpose, see the code I have added in edit and put your expression in the definition of `vowel` and check. Thanks. – Enamul Hassan Nov 03 '15 at 17:10
  • I only used `lex` about 15 years ago :) so I'm not sure lookahead is supported in `flex` or not. – anubhava Nov 03 '15 at 17:12
  • @anubhava: lookahead is not supported by flex, except for the trailing context operator which can only be at the end of the pattern. – rici Nov 03 '15 at 20:51
2

I'm going to use this character class [aeiou] containing the English vowels.

[^aeiou]*[aeiou]+...

Something like that above could work but you say it has to contain all of the vowels in no particular order. So to capture this intent you need something like this.

[^aeiou]*(a[^eiou]*|e[^aiou]*|i[^aeou]*|o[^aeiu]*|u[^aeio]*)...

Now do you see? We have to provide a lot of alterations and we have to nest them, in order to show that we're looking for what we haven't matched so far.

The idea is to condition each alteration and then progress as if we can assume that we're no longer looking for what we just matched. There's no trick just a lot of regex.

However, you need (n-1)(n-2)(n-3)... terms for this. With 5 vowels it could work but it's well... not ideal.

Just to show the absurdity of this. Here's the complete regex. And no, I did not write it by hand I wrote a small program to generate this.

[^aeiou]*(a[^eiou]*(e[^iou]*(i[^ou]*(o[^u]*(u)|u[^o]*(o))|o[^iu]*(i[^u]*(u)|u[^i]*(i))|u[^io]*(i[^o]*(o)|o[^i]*(i)))|i[^eou]*(e[^ou]*(o[^u]*(u)|u[^o]*(o))|o[^eu]*(e[^u]*(u)|u[^e]*(e))|u[^eo]*(e[^o]*(o)|o[^e]*(e)))|o[^eiu]*(e[^iu]*(i[^u]*(u)|u[^i]*(i))|i[^eu]*(e[^u]*(u)|u[^e]*(e))|u[^ei]*(e[^i]*(i)|i[^e]*(e)))|u[^eio]*(e[^io]*(i[^o]*(o)|o[^i]*(i))|i[^eo]*(e[^o]*(o)|o[^e]*(e))|o[^ei]*(e[^i]*(i)|i[^e]*(e))))|e[^aiou]*(a[^iou]*(i[^ou]*(o[^u]*(u)|u[^o]*(o))|o[^iu]*(i[^u]*(u)|u[^i]*(i))|u[^io]*(i[^o]*(o)|o[^i]*(i)))|i[^aou]*(a[^ou]*(o[^u]*(u)|u[^o]*(o))|o[^au]*(a[^u]*(u)|u[^a]*(a))|u[^ao]*(a[^o]*(o)|o[^a]*(a)))|o[^aiu]*(a[^iu]*(i[^u]*(u)|u[^i]*(i))|i[^au]*(a[^u]*(u)|u[^a]*(a))|u[^ai]*(a[^i]*(i)|i[^a]*(a)))|u[^aio]*(a[^io]*(i[^o]*(o)|o[^i]*(i))|i[^ao]*(a[^o]*(o)|o[^a]*(a))|o[^ai]*(a[^i]*(i)|i[^a]*(a))))|i[^aeou]*(a[^eou]*(e[^ou]*(o[^u]*(u)|u[^o]*(o))|o[^eu]*(e[^u]*(u)|u[^e]*(e))|u[^eo]*(e[^o]*(o)|o[^e]*(e)))|e[^aou]*(a[^ou]*(o[^u]*(u)|u[^o]*(o))|o[^au]*(a[^u]*(u)|u[^a]*(a))|u[^ao]*(a[^o]*(o)|o[^a]*(a)))|o[^aeu]*(a[^eu]*(e[^u]*(u)|u[^e]*(e))|e[^au]*(a[^u]*(u)|u[^a]*(a))|u[^ae]*(a[^e]*(e)|e[^a]*(a)))|u[^aeo]*(a[^eo]*(e[^o]*(o)|o[^e]*(e))|e[^ao]*(a[^o]*(o)|o[^a]*(a))|o[^ae]*(a[^e]*(e)|e[^a]*(a))))|o[^aeiu]*(a[^eiu]*(e[^iu]*(i[^u]*(u)|u[^i]*(i))|i[^eu]*(e[^u]*(u)|u[^e]*(e))|u[^ei]*(e[^i]*(i)|i[^e]*(e)))|e[^aiu]*(a[^iu]*(i[^u]*(u)|u[^i]*(i))|i[^au]*(a[^u]*(u)|u[^a]*(a))|u[^ai]*(a[^i]*(i)|i[^a]*(a)))|i[^aeu]*(a[^eu]*(e[^u]*(u)|u[^e]*(e))|e[^au]*(a[^u]*(u)|u[^a]*(a))|u[^ae]*(a[^e]*(e)|e[^a]*(a)))|u[^aei]*(a[^ei]*(e[^i]*(i)|i[^e]*(e))|e[^ai]*(a[^i]*(i)|i[^a]*(a))|i[^ae]*(a[^e]*(e)|e[^a]*(a))))|u[^aeio]*(a[^eio]*(e[^io]*(i[^o]*(o)|o[^i]*(i))|i[^eo]*(e[^o]*(o)|o[^e]*(e))|o[^ei]*(e[^i]*(i)|i[^e]*(e)))|e[^aio]*(a[^io]*(i[^o]*(o)|o[^i]*(i))|i[^ao]*(a[^o]*(o)|o[^a]*(a))|o[^ai]*(a[^i]*(i)|i[^a]*(a)))|i[^aeo]*(a[^eo]*(e[^o]*(o)|o[^e]*(e))|e[^ao]*(a[^o]*(o)|o[^a]*(a))|o[^ae]*(a[^e]*(e)|e[^a]*(a)))|o[^aei]*(a[^ei]*(e[^i]*(i)|i[^e]*(e))|e[^ai]*(a[^i]*(i)|i[^a]*(a))|i[^ae]*(a[^e]*(e)|e[^a]*(a)))))

Code to generate above regex:

static void Main(string[] args)
{
  var vowels = new HashSet<char>("aeiou".ToCharArray());
  var sb = new StringBuilder();
  BuildRegex(vowels, sb);
  Console.WriteLine(sb);
}

private static void BuildRegex(HashSet<char> vowels, StringBuilder sb)
{
  if (vowels.Count == 0)
  {
    return;
  }
  sb.Append("[^" + string.Join(string.Empty, vowels) + "]*");
  if (vowels.Count > 0)
  {
    sb.Append('(');
    int i = 0;
    foreach (var vowel in vowels.OrderBy(x => x))
    {
      var vowels2 = new HashSet<char>(vowels);
      vowels2.Remove(vowel);
      if (i > 0)
      {
        sb.Append('|');
      }
      sb.Append(vowel);
      BuildRegex(vowels2, sb);
      i++;
    }
    sb.Append(')');
  }
}
John Leidegren
  • 59,920
  • 20
  • 131
  • 152
  • Thanks for your hard work! but This does not work in my machine. I added my code in the question, paste your expression in the definition of `vowel` and check in your machine. – Enamul Hassan Nov 03 '15 at 17:05
  • It works on my machine. I tested it against the data you provided. The theory here is sound. If there's a problem it's either with the way flex does things or the fact that the regex I provided (which works in flex) is case sensitive. To match regardless of case you need to replace each `a` with `[Aa]` and each `[^eiou]` with `[^EeIiOoUu]`, etc. – John Leidegren Nov 03 '15 at 17:11
  • If it works for small letters then it would be fine, ignore capital letters as like other letters. Do the code gives the expected output which I have provided in the question for the corresponding input in your machine? It is not working here. – Enamul Hassan Nov 03 '15 at 17:15
  • There's one significant difference. I only test for a match. Regardless of the input string any arrangement of the vowels will be OK. However, flex will want to tokenize the complete string. For this to work you need to add something which captures the trailing characters, the last characters. – John Leidegren Nov 03 '15 at 17:18
  • Try adding `[a-z]*` at the very end (or equivalent depending on what you want to include in the token once we've concluded it has all the vowels. But be mindful of the **suffixes** because they might incorrectly be gobbled by something as greedy as `[a-z]*`. – John Leidegren Nov 03 '15 at 17:24
  • No improvement, give same result as before. – Enamul Hassan Nov 03 '15 at 17:35
  • I will not troubleshooting your flex file for you. I will leave you with this advice. Subtract from the problem everything else. That is, you're flex file is quite large at the moment. Start with only the bare minimum of what you're trying to do (address the issue with the vowels separately). Then when you know that each thing works by itself, test the different ways you can combine them. Be mindful when things don't go as expected and if necessary just start over but try it in a different way. I find that it helps my thinking when I try to write in text what I want to accomplish. – John Leidegren Nov 03 '15 at 20:32
  • I ran it with the regular expression you provided. but flex gives fatal error after running about 2 hours. – Enamul Hassan Nov 04 '15 at 10:15
  • @manetsus yeah OK, I guess flex isn't very good at dealing with large regular expressions. I tested it using the Microsoft .NET RegEx engine and it took no time at all. It's entirely possible that there's a different construction which is more efficient in the case of flex but I don't know what that would be. This works and I would guess that the problem lies with they way flex operates. – John Leidegren Nov 04 '15 at 11:02
  • A slight modification (replacing `[^xxx]` with `[a-z]{-}[xxx]`) works fine with flex 2.5.39; I'm not sure why it wouldn't work with earlier versions. If you don't go to the trouble of individually computing the exclusions for each repetition, then it will require effectively infinite memory to produce the DFA. – rici Nov 05 '15 at 04:35
1
static int array[5];


%%
[a-zA-Z]            {
                        int i = 0;
                        for (i = 0; i < 5' i++ {
                            array[i] = 0;
                        }
                        char a;
                        i = 0;
                        for (a = yytext[i]; a != '\0'; i++) {
                            if (a == 'a') {
                                array[0] = 1;
                            }
                            if (a == 'e') {
                                array[1] = 1;
                            }
                            if (a == 'i') {
                                array[2] = 1;
                            }
                            if (a == 'o') {
                                array[3] = 1;
                            }
                            if (a == 'u') {
                                array[4] = 1;
                            }
                        }
                        if (array[0] == 1 && array[1] == 1 && array[2] == 1 && array[3] == 1 && array[4] == 1) {
                            printf("VOWELS\n");
                        }
                    }
%%

Regular expression:

a.*e.*i.*o.*u|a.*e.*i.*u.*o|a.*e.*o.*i.*u|a.*e.*o.*u.*i|a.*e.*u.*i.*o|a.*e.*u.*o.*i|a.*i.*e.*o.*u|a.*i.*e.*u.*o|a.*i.*o.*e.*u|a.*i.*o.*u.*e|a.*i.*u.*e.*o|a.*i.*u.*o.*e|a.*o.*e.*i.*u|a.*o.*e.*u.*i|a.*o.*i.*e.*u|a.*o.*i.*u.*e|a.*o.*u.*e.*i|a.*o.*u.*i.*e|a.*u.*e.*i.*o|a.*u.*e.*o.*i|a.*u.*i.*e.*o|a.*u.*i.*o.*e|a.*u.*o.*e.*i|a.*u.*o.*i.*e|e.*a.*i.*o.*u|e.*a.*i.*u.*o|e.*a.*o.*i.*u|e.*a.*o.*u.*i|e.*a.*u.*i.*o|e.*a.*u.*o.*i|e.*i.*a.*o.*u|e.*i.*a.*u.*o|e.*i.*o.*a.*u|e.*i.*o.*u.*a|e.*i.*u.*a.*o|e.*i.*u.*o.*a|e.*o.*a.*i.*u|e.*o.*a.*u.*i|e.*o.*i.*a.*u|e.*o.*i.*u.*a|e.*o.*u.*a.*i|e.*o.*u.*i.*a|e.*u.*a.*i.*o|e.*u.*a.*o.*i|e.*u.*i.*a.*o|e.*u.*i.*o.*a|e.*u.*o.*a.*i|e.*u.*o.*i.*a|i.*a.*e.*o.*u|i.*a.*e.*u.*o|i.*a.*o.*e.*u|i.*a.*o.*u.*e|i.*a.*u.*e.*o|i.*a.*u.*o.*e|i.*e.*a.*o.*u|i.*e.*a.*u.*o|i.*e.*o.*a.*u|i.*e.*o.*u.*a|i.*e.*u.*a.*o|i.*e.*u.*o.*a|i.*o.*a.*e.*u|i.*o.*a.*u.*e|i.*o.*e.*a.*u|i.*o.*e.*u.*a|i.*o.*u.*a.*e|i.*o.*u.*e.*a|i.*u.*a.*e.*o|i.*u.*a.*o.*e|i.*u.*e.*a.*o|i.*u.*e.*o.*a|i.*u.*o.*a.*e|i.*u.*o.*e.*a|o.*a.*e.*i.*u|o.*a.*e.*u.*i|o.*a.*i.*e.*u|o.*a.*i.*u.*e|o.*a.*u.*e.*i|o.*a.*u.*i.*e|o.*e.*a.*i.*u|o.*e.*a.*u.*i|o.*e.*i.*a.*u|o.*e.*i.*u.*a|o.*e.*u.*a.*i|o.*e.*u.*i.*a|o.*i.*a.*e.*u|o.*i.*a.*u.*e|o.*i.*e.*a.*u|o.*i.*e.*u.*a|o.*i.*u.*a.*e|o.*i.*u.*e.*a|o.*u.*a.*e.*i|o.*u.*a.*i.*e|o.*u.*e.*a.*i|o.*u.*e.*i.*a|o.*u.*i.*a.*e|o.*u.*i.*e.*a|u.*a.*e.*i.*o|u.*a.*e.*o.*i|u.*a.*i.*e.*o|u.*a.*i.*o.*e|u.*a.*o.*e.*i|u.*a.*o.*i.*e|u.*e.*a.*i.*o|u.*e.*a.*o.*i|u.*e.*i.*a.*o|u.*e.*i.*o.*a|u.*e.*o.*a.*i|u.*e.*o.*i.*a|u.*i.*a.*e.*o|u.*i.*a.*o.*e|u.*i.*e.*a.*o|u.*i.*e.*o.*a|u.*i.*o.*a.*e|u.*i.*o.*e.*a|u.*o.*a.*e.*i|u.*o.*a.*i.*e|u.*o.*e.*a.*i|u.*o.*e.*i.*a|u.*o.*i.*a.*e|u.*o.*i.*e.*a

Simply replace dots with [a-zA-Z].

xenteros
  • 15,586
  • 12
  • 56
  • 91
  • I thought this idea before, but think about the string `speaously` which would not be marked as `VOWELS` as it has no `i`. then how would I match the next regular expressions? – Enamul Hassan Nov 03 '15 at 17:43
  • Well, there are words, that match both: VOWELS and ADVERB. Do you want to print both or just one, anyway, when you have a word, just check it in code. When this loop through letters of yytext ends, you have yytext's length. Nothing stops you from checking last two letters of the string. – xenteros Nov 03 '15 at 17:47
  • According to your solution all other regular expressions should be handled in C code, which is not my purpose. actually. – Enamul Hassan Nov 03 '15 at 17:50
  • `flex` crashes while trying to implement with 120 regular expressions! – Enamul Hassan Nov 03 '15 at 18:44
0

Actually this is not possible by flex. Because, I have tried the following with no luck.

  1. At first, I tried to run flex program with all 5! combinations, but it crashed immediately!
  2. Then I ran the flex program with a reduced form of 5! combinations for more than an hour, but after that it gave a fatal error! message!

So, I have concluded with the decision that it is not possible with flex.

Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56