Skip to content

Instantly share code, notes, and snippets.

@seanwu1105
Created March 22, 2018 10:50
Show Gist options
  • Save seanwu1105/034b9cb71d2af9d516ee78fbf0efc1e3 to your computer and use it in GitHub Desktop.
Save seanwu1105/034b9cb71d2af9d516ee78fbf0efc1e3 to your computer and use it in GitHub Desktop.
The LEX to filter the IPv4 format.
%{
#include <iostream>
#include <string>
%}
integer_in_ipv4 0|1([0-9][0-9]?)?|2([5-9]|[0-4][0-9]?|5[0-5]?)?|[3-9][0-9]?
ipv4 {integer_in_ipv4}\.{integer_in_ipv4}\.{integer_in_ipv4}\.{integer_in_ipv4}
%%
{ipv4} {ECHO; printf("\n");}
.
\n
%%
int main(void)
{
yylex();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment