Question: .Python. Can someone help me with my code on the characters that it validates? Acceptable input is zero or more characters from these characters only

.Python.

Can someone help me with my code on the characters that it validates? Acceptable input is zero or more characters from these characters only {a, b, +, *, (, )}. and make the program show what characters are invalid like the sample.

import re valid_chars = "[a\b\|\*\(\)]"

print("Regular expression validator over the alphabet {a,b, |, *, (, )}") # intructions for the user

while True: expression = input("Enter regular expression: ") if expression == "": break if re.fullmatch(valid_chars, expression): print("VALID:", expression) else: invalid_chars = "".join(re.findall("[^c-zA-Z\0-9\!\@\#\$\%\&]", expression)) <- I do not know how to put everything that is invalid in here print("INVALID:", expression)

for char in invalid_chars: print("^", end="") print()

print("Program terminated.")

here is the sample input and output Regular expression validator over the alphabet {a, b, +, *, (, )} Enter regular expression: ab VALID: ab Enter regular expression: ab ( ba)* VALID: ab(ba)* Enter regular expression: ab ( ba)*X+ba ( bb INVALID: ab(ba)*X+ba(bb ^^ Enter regular expression: ) & 0 # $ b ( - b a)*X | ba ( bb INVALID: )&a#$b(-ba)*X | ba(bb ^ ^^ ^ ^ Program terminated.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!