Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

.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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions