/** * Stephanie Taylor * Spring 2026 * CS333 * * Read one line at a time from the command line and identify patterns * This intends to demo all of the special characters listed in the notes. * * flex -o demo_special_characters.yy.c demo_special_characters.yy * gcc -o demo_special_characters demo_special_characters.yy.c -ll []: used to specify a set of single character alternatives (different from EBNF) [AEIOU]: one uppercase vowel T[ao]p: tap, top [0-9]: you can use ranges \: used as an escape character to permit use of other special character \s: whitespace Write a regex to match all CS courses. [CS\s[0-9][0-9][0-9] matches CS XXX] Note that \d is available in egrep, and it matches a single digit \ can also be used to escape the meaning of a special character. E.g. if you want to look for the literal character “[“, then use \[. If your string is “[hi]”, you can match it with “\[..\]”, but not “[..]”. . : matches almost any character except line breaks a.e: water, ate, gate * : match the prior expression zero or more times \. : decimal point Write a regex to match floating point values with one digit after the decimal points. [\d*\.\d: .3, 12.5, 139.9] - : range indicator [a-z]: one lowercase letter from a to z ^: negates an expression when inside brackets, permits you to specify strings that don’t include a certain expression, or is the start of the string otherwise [^0-9]: matches any character that is not a digit ^a: matches strings start with a $: the end of the string the end$: this is the end Write a regex that can match any number between 1000 and 9999. ^[1-9][0-9][0-9][0-9]$ create a text.txt with following numbers, one on each line, 1231 21 5 57 0101 100001 1000a; key in the command egrep “^[1-9][0-9][0-9][0-9]$” text.txt; this command returns the matches in text.txt. () : group tokens (different from EBNF) th(e|is) : the, this + : match the prior expression one or more times html tags: ,

,
<[A-Za-z][A-Za-z0-9]*>: matches HTML tags without any attributes <[A-Za-z0-9]+>: matches HTML tags without any attributes, but can have invalid tag like <1> <[^< >]+> : matches HTML tags without regard to attributes {min, max} : specify how many times a token can be repeated, min >=0 minimum number of matches, max >= min maximum number of matches. If {min, } the maximum number of matches is infinite. {min} repeat exactly min times. {0, } same as *, {1, } same as + ^[1-9][0-9]{3}$: matches a number between 1000 and 9999 ^[1-9][0-9]{2,4}$: matches a number between 100 and 99999 ? : once or none */ DIGIT [0-9] %% end$ printf( "Found end ending: %s\n", yytext ); earth(Inner|Middle)earth printf( "Found inner or middle earth: %s\n", yytext ); [AEIOU]? printf( "Found 0 or 1 uppercase vowel: %s\n", yytext ); ^[1-9][0-9]{3}$ printf( "found a number between 1000 and 9999: %s\n", yytext ); {DIGIT}+ printf( "found a sequence of one or more decimal digits: %s\n", yytext ); \. printf( "found a dot: %s\n", yytext ); . printf( "found any character: %s\n", yytext ); %% int main( int argc, char *argv[] ) { yylex(); // a function of flex that read input till it is exhausted return 0; }