-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregexvalidator.py
48 lines (43 loc) · 1.68 KB
/
regexvalidator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from tkinter import *
import re
root=Tk()
root.configure(background='#00001a')
root.geometry("1000x350+300+300")
root.title("Regular Expression Validator")
regex=StringVar()
ex=StringVar()
answer=StringVar()
#functions definitions
def validate():
regex1=regex.get()
example=ex.get()
try:
if re.match(regex1, example):
regexvalid=re.compile(regex1)
ans=regexvalid.findall(example)
ansstr="Matches:"
for i in ans:
ansstr+="\t"+i
answer.set(ansstr)
else:
answer.set("No matches")
except:
answer.set("Invalid Regular Expression")
#creating buttons, labels and entries
labelhead=Label(root, text="Regex Validator", font="Arial 25 bold underline", width=50, height=2, fg="#00001a", bg="#ffcc99")
labelhead.grid(columnspan=2)
label1=Label(root, text="Regular Expression: ", padx=5, pady=20, font="Arial 18", bg="#00001a", fg="#ffcc99")
label1.grid(row=1, column=0)
entryreg=Entry(root, textvariable=regex, font="Arial 18", bg="#ffcc99")
entryreg.grid(row=1, column=1)
label2=Label(root, text="Test Example: ", padx=5, pady=5, font="Arial 18", bg="#00001a", fg="#ffcc99")
label2.grid(row=2, column=0)
entryex=Entry(root, textvariable=ex, font="Arial 18", bg="#ffcc99")
entryex.grid(row=2, column=1)
anslabel=Label(root, textvariable=answer, width=50, font="Arial 16", fg="#ffcc99", bg="#00001a", pady=15)
submit=Button(root, text="Submit", command=validate, font="Arial 18", bg="#ffcc99", width=10)
exitbtn=Button(root, text="Exit", command=root.destroy, font="Arial 18", bg="#ffcc99", width=10)
anslabel.grid(columnspan=2)
submit.grid(row=4, column=0)
exitbtn.grid(row=4, column=1)
root.mainloop()