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"); } |
chevron_right
filter_none
Output:

Recommended Posts:
- Lex Program to check valid email
- Lex program to check if a Date is valid or not
- Lex Program to accept a valid integer and float value
- Lex program to check valid Mobile Number
- Lex program to recognize valid arithmetic expression and identify the identifiers and operators
- YACC program to implement a Calculator and recognize a valid Arithmetic expression
- C program to detect tokens in a C program
- Lex Program to remove comments from C program
- Lex program to identify the identifier
- Lex program to check whether a given number is even or odd
- Lex Program to count number of words
- LEX program to add line numbers to a given file
- YACC program to recognize strings of { anb | n≥5 }
- Lex program for Decimal to Binary Conversion
- Lex program to count words that are less than 10 and greater than 5
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



