<jupyter_start><jupyter_text>Regular Expression<jupyter_code>import re
re_test = 'This is a made up string to test 2 different regex methods'
re_test_messy = 'This      is a made up     string to test 2    different regex methods'
re_test_messy1 = 'This-is-a-made/up.string*to>>>>test----2""""""different~regex-methods'<jupyter_output><empty_output><jupyter_text>1 st method -----> re.split()<jupyter_code># re_test
re.split('\s',re_test)
# re_test_messy
import re
re.split('\s',re_test_messy)
re.split('\s+',re_test_messy)
# re_test_messy1
re.split('\s',re_test_messy1)
re.split('\s+',re_test_messy1)
re.split('\w',re_test_messy1)
re.split('\W',re_test_messy1)
re.split('\W+',re_test_messy1)<jupyter_output><empty_output><jupyter_text>2nd method ---> re.findall()<jupyter_code>re.findall('\S+',re_test)
re.findall('\S+',re_test_messy)
re.findall('\S+',re_test_messy1)
re.findall('\w+',re_test_messy1)<jupyter_output><empty_output><jupyter_text>Replacing a Specific String<jupyter_code>pep8_test = 'I try to follow PEP8 guidelines'
pep7_test = 'I try to follow PEP7 guidelines'
peep8_test = 'I try to follow PEEP8 guidelines'
re.findall('[a-z]+',pep8_test)
re.findall('[A-Z]+',pep8_test)
re.findall('[A-Z0-9]+',pep8_test)
re.findall('[A-Z]+[0-9]+',pep8_test)
re.sub('[A-Z]+[0-9]+','PYTHON REGEX MODULE',pep8_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18317200297840655, 'fraction_numerical': 0.02308265078183172, 'mean_word_length': 7.3478260869565215, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '119767', 'license': 'MIT', 'n_tokens_mistral': 609, 'n_tokens_neox': 596, 'n_words': 82, 'path': 'Linkedin/NLP/CH01/regex.ipynb', 'repo_name': 'Dhaneshgupta1027/Python', 'size': '1343'}