Lex Program For checking a valid URL
Problem: Write a Lex program for checking a valid URL.
Explanation:
Lex is a computer utility that generates some lexical analyzers. Lex reads a stream of characters as input specifying the lexical analyzer and give source code as the output implementing the lexer in the C programming language.
Prerequisite: Flex (Fast Lexical Analyzer Generator)
Examples:
Input: geeksforgeeks
Output: INVALID URL
Input: https://www.geeksforgeeks.org
Output: VALID URL
Implementation:
%%
((http)|(ftp))s?:\/\/[a-zA-Z0-9]{2, }(\.[a-z]{2, })
+(\/[a-zA-Z0-9+=?]*)* { printf ( "\nURL Valid\n" );}
.+ { printf ( "\nURL Invalid\n" );}
%%
void main()
{
printf ( "\nEnter URL : " );
yylex();
printf ( "\n" );
}
|
Output:
Last Updated :
02 May, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...