<commit_before>#!/Applications/anaconda/envs/Python3/bin

import re

def main():
    '''Examples Using Regular Expressions in Python'''

    fh = open('sonnets.txt')
    # Use raw string for backslash, other special characters
    # Prints the Roman Numerals before each sonnet
    pattern = re.compile(r'[IVXLCDM]+\.')
    for line in fh:
        if re.search(pattern, line):
            print(line, end='')


    return 0


if __name__ == '__main__':<commit_msg>Refactor regex.py, improve Shakespeare's sonnets<commit_after>#!/Applications/anaconda/envs/Python3/bin

import re

def main():
    '''Examples Using Regular Expressions in Python'''

    printRomanNumerals('sonnets.txt')
    replaceWord('sonnets.txt', 'beauty', 'vomit')

    return 0


def printRomanNumerals(filename):
    '''Reads filename data and prints Roman Numerals followed by .'''

    fh = open(filename, 'r')
    # Use raw string for backslash, other special characters
    pattern = re.compile(r'[IVXLCDM]+\.')
    for line in fh:
        match = re.search(pattern, line)
        if match:
            print(match.group())


    fh.close()
    return 0


def replaceWord(filename, original, new):
    '''Prints any line with original word in it replaced with new word'''

    print('\nTime to replace the word {} with {} and print the improved line.\n'.format(original, new))

    fh = open(filename, 'r')
    pattern = re.compile(original)
    for line in fh:
        if re.search(pattern, line):
            print(pattern.sub(new, line), end='')
            #print(re.sub(pattern, new, line), end='')

    fh.close()
    return 0


if __name__ == '__main__':
{'fraction_non_alphanumeric': 0.1282051282051282, 'fraction_numerical': 0.003663003663003663, 'mean_word_length': 3.0369458128078817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '293822', 'n_tokens_mistral': 541, 'n_tokens_neox': 495, 'n_words': 154}