# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: 'Python 3.7.6 64-bit (''base'': conda)'
#     name: python376jvsc74a57bd0ec4f1c395c9060a2f4933d56a58278157b2fbfb1d142affcb202d55b2721a26e
# ---

text = "The agent's phone number is 408-555-1234. Call soon! phone"

'phone' in text

import re

pattern = 'phone'

# +
x = re.search(pattern,text) 

x.group()
# -

s = text[12:17]
s

for match in re.finditer('phone',text):
  print(match.span())

# +
# usando patrones regex

text = 'my phone number is 408-555-1234'

phone = re.search(r'\d{3}-\d{3}-\d{4}',text)
phone2 = re.search(r'\d\d\d-\d\d\d-\d\d\d\d',text)

print(phone,phone2)



# +
# comile

phone_pattern = re.compile(r'(\d{3})-(\d{3})-(\d{4})')

phone = re.search(phone_pattern,text)
# -

phone

# +
# or operator 

r = re.search(r'cat|dog', 'dog is here')
'dog is here'[0:3]
# -

re.findall(r'..at..', 'the cat in the hat went splat')

re.findall(r'^\d', 'hello man')

re.findall(r'\d$', 'the number is 2')

# +
phrase = 'there are 3 numbers 34 inside 5 this sentece'

exclude_pattern = r'[^\d]'

print(re.findall(exclude_pattern, phrase))


# -

exclude_pattern = r'[^\d]+'
print(re.findall(exclude_pattern, phrase))

# +
test_phrase = 'This is a string! But it has a puntuation. How can we remove it?'

clean_phrase = re.findall(r'[^!.? ]+', test_phrase)
print(clean_phrase)
# -

' '.join(clean_phrase)

# +
phrase = 'frase-test para incluir solo ciertos caracteres tales como grupoLetras-grupoLetras'

pattern= r'[\w]+-[\w]+'

re.findall(pattern, phrase)

# +
phrase = 'hola, quiero comer panacota'
phrase2 = 'hola, quiero ir a una panaderia'

re.search(r'pan(acota|aderia)', phrase2)
# -

phrase2.split()

# +
words = filter(lambda word : re.search(r'^pan',word), phrase2.split())

list(words)

StarcoderdataJupyterScriptsDedupFiltered