regular expressions in python the input file will have multiple proposed tokens on e 5154279
Regular expressions in python
* The input file will have multiple proposed tokens on each
line. There also might be lines with no proposed tokens and/ or just or extra whitespace.
* The proposed tokens will be separated by whitespace, which is
to be ignored.
* Your program will consider successive tokens from the input
file and classify them as 'EffPea', 'Stir', 'Ent', or
'does not match'.
* An “EffPea” is one or more vowels 'a', 'e', 'i', 'o', 'u',
'A', 'E', 'I', 'O', 'U', followed by a left brace '{',
followed by a right parenthesis ')', followed by one or more
hexadecimal digits '0' through '9', 'a' through 'f', 'A'
through 'F'.9
* A “Stir” is a right brace '}' followed by zero or more
lowercase letters 'a' through 'z' and decimal digits '0'
through '9', followed by a left parenthesis '('.
* An “Ent” is an at sign '@', followed by one or more decimal
digits '0' through '9' or uppercase letters 'R' through 'W',
followed by an octothorpe sign '#'.
a{)0 — legal EffPea
eieio{)000AAAfff — legal EffPea
aAeEiIoOuU{)0123456789abcdefABCDEF — legal EffPea
ba{)9 — illegal EffPea, b is not a vowel
u){b — illegal EffPea, ){ is not {)
{)a — illegal EffPea, no vowel in front of {)
}q( — legal Stir
}r1s23( — legal Stir
}( — legal Stir
{great( — illegal Stir, { is not }
}(a — illegal Stir, a is after (
{Wrong( — illegal Stir, W is uppercase
@RTW# — legal Ent
@0S9V# — legal Ent
@999# — legal Ent
834# — illegal Ent, no @ at front
@tvw# — illegal Ent, tvw are lowercase
@ABC# — illegal Ent, ABC are not in R through W
CURRENT PROGRAM:
#————————————————–
import re
import sys
#————————————————–
def processToken( token ) :
# Replace the following line with your code to classify
# the string in 'token' according to your three Regular
# Expressions and print the appropriate message.
print( '>%s
#————————————————–
def main() :
fName = sys.argv[ 1 ]
print( 'processing tokens from ' + fName + ' …' )
with open( fName, 'r' ) as fp :
lines = fp.read().replace( 'r', '' ).split( 'n' )
for line in lines :
for token in line.split() :
processToken( token )
#————————————————–
if ( __name__ == '__main__' ) :
main()
#————————————————–
processing tokens from inputdata.txt …
>a{)0
>eieio{)000AAAfff
>aAeEiIoOuU{)0123456789abcdefABCDEF
>ba{)9
>u){b
>{)a
>}q(
>}r1s23(
>}(
>{great(
>}(a
>{Wrong(
>@RTW#
>@0S9V#
>@999#
>834#
>@tvw#
>@ABC#
a{)0
eieio{)000AAAfff
aAeEiIoOuU{)0123456789abcdefABCDEF
ba{)9
u){b
{)a
}q(
}r1s23(
}(
{great(
}(a
{Wrong(
@RTW#
@0S9V#
@999#
834#
@tvw#
@ABC#
OUTPUT DATA:
processing tokens from inputdata.txt …
>a{)0
>eieio{)000AAAfff
>aAeEiIoOuU{)0123456789abcdefABCDEF
>ba{)9
>u){b
>{)a
>}q(
>}r1s23(
>}(
>{great(
>}(a
>{Wrong(
>@RTW#
>@0S9V#
>@999#
>834#
>@tvw#
>@ABC#