<jupyter_start><jupyter_text>Match a string with a pattern - re.match(pattern, string)<jupyter_code>results = re.match('Pioneer', 'Pioneer Alpha is an emerging AI startup.')
results.group(0)
results = re.match('Pioneer Alpha', 'Pioneer Alpha is an emerging AI startup.')
results.group(0)<jupyter_output><empty_output><jupyter_text>Search a string - re.search(pattern, string)<jupyter_code>results = re.search('Alpha', 'Pioneer Alpha is an emerging AI startup.')
results.group(0)<jupyter_output><empty_output><jupyter_text>Find all string- re.findall(pattern,string)<jupyter_code>pattern = "Pioneer"

target = 'Pioneer Alpha is a pioneer AI startup.'

results = re.findall(pattern.lower(), target.lower())
results<jupyter_output><empty_output><jupyter_text>Split string by occurances of given pattern<jupyter_code>results = re.split(r"\\", "AI\ML")
results<jupyter_output><empty_output><jupyter_text>Find a pattern and replace with a new substring- re.sub(pattern,replace_with,string)<jupyter_code>results = re.sub('an', 'an emering' , 'Pioneer Alpha is an AI startup. Pioneer Alpha is an AI startup.')
results<jupyter_output><empty_output><jupyter_text>Understanding Special Symbols<jupyter_code># Find all characters
result = re.findall(r'.','Pioneer Alpha is an AI startup. Pioneer Alpha is an AI startup.')
result
# Find all alphanumeric charater
result = re.findall(r'\w','Pioneer Alpha is an AI startup. Pioneer Alpha is an AI startup.')
result<jupyter_output><empty_output><jupyter_text>Some Real-life Examples<jupyter_code># Find all words
result = re.findall(r'\w*','Pioneer Alpha is an AI startup. Pioneer Alpha is an AI startup.')
result
result = re.findall(r'\w+','Pioneer Alpha is an AI startup. Pioneer Alpha is an AI startup.')
result
# 3 consecutive seperate characters of all words
result = re.findall(r'\w\w\w','Pioneer Alpha is an AI startup. Pioneer Alpha is an AI startup.')
result
# First 3 first characters of each word
result = re.findall(r'\b\w\w.','Pioneer Alpha is an AI startup. Pioneer Alpha is an AI startup.')
result
# First 2 last characters of each word
result = re.findall(r'\w\w\b','Pioneer Alpha is an AI startup. Pioneer Alpha is an AI startup.')
result
# Extract Emails from a text
result = re.findall(r'\w+@\S+','Email us at: <EMAIL> For more details: <EMAIL>')
result
# Extract urls from a text
result = re.findall(r'http\S+','Email us at: <EMAIL> For more details: https://pioneeralpha.com/')
result
# (?), (*), (+)
sent = "cl cls class classy classsy"
pattern1 = r"cla?s"
pattern2 = r"cla?s*"
pattern3 = r"cla?s+"

result1 = re.findall(pattern1,sent)
result2 = re.findall(pattern2,sent)
result3 = re.findall(pattern3,sent)

print(result1)
print(result2)
print(result3)
# Extract only words with alphabets
# Use of Sets
result = re.findall(r'[a-zA-Z]+','Email us at: <EMAIL> For more details: https://pioneeralpha.com/')
result
# Extract only amounts
result = re.findall(r'[\d,]+','COVID-19 put a massive blow to the human kind. The death toll is over 4,500,000.')
result<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup