<jupyter_start><jupyter_text>Regular Expressions Quiz*Prepared by:***<NAME>**  Faculty, Software Technology Department  College of Computer Studies - De La Salle University This notebook is for assessing your basic programming and regex skills in Python. Answer as many as you can.**Total points: 50****Note that the assert cells will return an error if you have not implemented the previous cells correctly.**  Preliminaries  Import library<jupyter_code>import re<jupyter_output><empty_output><jupyter_text>Exercise 1. 5 pts.Read the logs from the following URL: https://raw.githubusercontent.com/Cyntwikip/data-repository/main/logs.txt, and assign it to a variable named `logs`. Make sure that it is a string.Hint! Google.<jupyter_code>url = "https://raw.githubusercontent.com/Cyntwikip/data-repository/main/logs.txt"

# YOUR CODE HERE
# DO NOT EDIT THIS
assert type(logs) == str<jupyter_output><empty_output><jupyter_text>Exercise 2. 15 pts.*+3 pts for one-line answer.*Create a capture group for each datetime element and store each entry in a list named `time_list`.Example:   [{‘year’: 2020, ‘month’: 01, ‘day’:12, ‘hour’:10, ‘minute’:10, ‘second’:35},  {‘year’: 2019, ‘month’: 06, ‘day’:12, ‘hour’:10, ‘minute’:10, ‘second’:35},  ...]<jupyter_code># YOUR CODE HERE
# DO NOT EDIT THIS
assert time_list == [{'year': '2018',
  'month': '07',
  'day': '12',
  'hour': '10',
  'minute': '53',
  'second': '32'},
 {'year': '2018',
  'month': '07',
  'day': '12',
  'hour': '10',
  'minute': '54',
  'second': '14'},
 {'year': '2018',
  'month': '07',
  'day': '12',
  'hour': '10',
  'minute': '54',
  'second': '17'},
 {'year': '2018',
  'month': '07',
  'day': '12',
  'hour': '10',
  'minute': '54',
  'second': '20'}]<jupyter_output><empty_output><jupyter_text>Exercise 3. 2 pts.Convert the `time_list` variable into a Pandas DataFrame.<jupyter_code># YOUR CODE HERE<jupyter_output><empty_output><jupyter_text>Exercise 4. 5 pts.Get all the IP addresses including the ports after `[INFO]` in the logs and assign it to a variable named `ip_list`.For ex. 127.0.0.1:57534<jupyter_code>pattern = # YOUR REGEX PATTERN HERE
# DO NOT EDIT THIS
ip_list = re.findall(pattern, logs)
assert ip_list == ['127.0.0.1:57534', '127.0.0.1:57534', '127.0.0.1:57534', '127.0.0.1:57534']<jupyter_output><empty_output><jupyter_text>Exercise 5. 15 pts.Create a regex for DLSU email addresses. Here are the rules:- it should end with `@dlsu.edu.ph`- the prefix can have `2 or more words`- the words in the prefix can only be joined using the following special characters: `_` and `.`- the email is in lowercase format.For example:- <EMAIL>- <EMAIL>- <EMAIL>The following are invalid:- <EMAIL>- <EMAIL>- <EMAIL>- <EMAIL><jupyter_code>pattern = # YOUR REGEX PATTERN HERE
# DO NOT EDIT THIS
emails = '''<EMAIL>
<EMAIL>
<EMAIL>
<EMAIL>
<EMAIL>
<EMAIL>
<EMAIL>
.<EMAIL>
<EMAIL>
<EMAIL>'''

email_list = re.findall(pattern, emails, re.M)
assert email_list == ['<EMAIL>', '<EMAIL>', '<EMAIL>']<jupyter_output><empty_output><jupyter_text>Exercise 6. 8 pts.Create a regex that captures any number. The digit may be a float or an integer and may or may not contain a sign.The following examples are valid:  10  1.96  +3.14  -3  -6.07  +3.The following examples are invalid:  1..96  3+14  /6.28  3.14.14<jupyter_code>pattern = # YOUR REGEX PATTERN HERE
# DO NOT EDIT THIS
numbers = '''1.96
+3.14
-3
-6.07
+3.
1..96
3+14
/6.28
3.14.14
10'''

num_list = re.findall(pattern, numbers, re.M)
assert num_list == ['1.96', '+3.14', '-3', '-6.07', '+3.', '10']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16586876936074346, 'fraction_numerical': 0.06308082230357646, 'mean_word_length': 4.775609756097561, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 50, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '295854', 'license': 'MIT', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1312, 'n_words': 408, 'path': 'preprocessing/regex-quiz.ipynb', 'repo_name': 'Cyntwikip/Data-Mining', 'size': '3866'}