<jupyter_start><jupyter_text>Python Regular Expression Quick Guide^        Matches the beginning of a line$        Matches the end of the line.        Matches any character\s       Matches whitespace\S       Matches any non-whitespace character*        Repeats a character zero or more times*?       Repeats a character zero or more times(non-greedy)+        Repeats a character one or more times+?       Repeats a character one or more times(non-greedy)[aeiou]  Matches a single character in the listed set[^XYZ]   Matches a single character not in the listed set[a-z0-9] The set of characters can include a range(        Indicates where string extraction is to start)        Indicates where string extraction is to end  Trying to solve the assignment with the sample data<jupyter_code># using the sample data to verify the code

import urllib.request
import re

sample_url = 'http://python-data.dr-chuck.net/regex_sum_42.txt'

with urllib.request.urlopen(sample_url) as response:
   html = response.read()

html_string = str(html)
numbers = re.findall('[0-9]+', html_string)

intlist = [int(x) for x in numbers]

len(intlist)
sum(intlist)
# using the actual data to calculate the answer

# import libraries
import urllib.request
import re

# name the URL
actual_url = 'http://python-data.dr-chuck.net/regex_sum_371509.txt'

# use the most basic of reading methods shown at the urllib.request project page
with urllib.request.urlopen(actual_url) as response:
   html = response.read()

# make the output into a string so that regex can be used
html_string = str(html)

# find all numbers with regex and put them into a list
numbers = re.findall('[0-9]+', html_string)

# transform the list entries to integers, one by one
intlist = [int(x) for x in numbers]

# calculate the sum of the integers in the list
#len(intlist)
sum(intlist)
# making a one-liner for fun
import urllib.request
import re

actual_url = 'http://python-data.dr-chuck.net/regex_sum_371509.txt'

with urllib.request.urlopen(actual_url) as response:
   html = response.read()

# here comes the line
sum([int(x) for x in re.findall('[0-9]+', str(html))])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08550185873605948, 'fraction_numerical': 0.010223048327137546, 'mean_word_length': 4.006976744186047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '602692', 'license': 'MIT', 'n_tokens_mistral': 689, 'n_tokens_neox': 670, 'n_words': 254, 'path': 'notebooks/Regex_codesamples.ipynb', 'repo_name': 'johanfrisk/Python_at_web', 'size': '2152'}