diff --git a/app/log.txt b/app/log.txt new file mode 100644 index 0000000..d2e9968 --- /dev/null +++ b/app/log.txt @@ -0,0 +1 @@ +this is some test [Animaslsd] sdtri \ No newline at end of file diff --git a/app/test_num.py b/app/test_num.py new file mode 100644 index 0000000..7e75d0c --- /dev/null +++ b/app/test_num.py @@ -0,0 +1,3 @@ +b = 5 +a = 2 +assert b < a \ No newline at end of file diff --git a/app/test_regex.py b/app/test_regex.py new file mode 100644 index 0000000..01ae111 --- /dev/null +++ b/app/test_regex.py @@ -0,0 +1,33 @@ +""" +Content of "log.txt": +10.1.2.1 - car [01/Mar/2022:13:05:05 +0900] "GET /python HTTP/1.0" 200 2222 +10.1.1.9 - bike [01/Mar/2022:13:05:10 +0900] "GET /python HTTP/1.0" 200 2222 + +Expected output: +01/Mar/2022:13:05:05 +0900 +01/Mar/2022:13:05:10 +0900 +""" +import re + +def parse1(): + for line in open("log.txt"): + print(line.split("[")[1].split("]")[0]) + assert True + +def parse2(): + for line in open("log.txt", "r"): + print(line.split()[3].strip("[]")) + assert False + +def parse3(): + for line in open("log.txt", "r"): + print(" ".join(line.split("[" or "]")[3:5])) + assert True + +print('Hello World') +parse3() + + +if __name__ == "__main__": + parse1() + parse3()