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" );} %% // driver program void main() { printf ( "\nEnter URL : " ); yylex(); printf ( "\n" ); } |
Output: