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