<jupyter_start><jupyter_text>Several examples on how to use regex on text fields<jupyter_code>import pandas as pd

df = pd.read_csv('./happiness-report.csv')
#check the data
df.head()
# Match and extract first lowercase letter after first occurence of 'e'.

df['letter_after_first_e']=df['Country (region)'].str.extract(r'(e[a-z]{1})')

df.head()
# Let's see countries that start with 'F'

df[df['Country (region)'].str.count(r'(^F.*)')==1]
# Or let's simply see how many of those countries we have in the report

df['Country (region)'].str.count(r'(^F.*)').sum()
# Here we look at countries starting with 'R' using match - which returns a boolen

df[df['Country (region)'].str.match('^R.*')== True]
# Let's find all records where there's an i in the middle

df[df['Country (region)'].str.contains('^.i.*')==True]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17556346381969157, 'fraction_numerical': 0.002372479240806643, 'mean_word_length': 5.59375, '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': '411823', 'license': 'MIT', 'n_tokens_mistral': 299, 'n_tokens_neox': 289, 'n_words': 88, 'path': 'Regex the happiness.ipynb', 'repo_name': 'KajoRudzinski/Regex-Excercise-Happines-Report', 'size': '843'}