Skip to content

Instantly share code, notes, and snippets.

@marcusrehm
Created November 7, 2017 13:10
Show Gist options
  • Save marcusrehm/ca579d5d9bb91e9ad0194d4a9b0fbb1e to your computer and use it in GitHub Desktop.
Save marcusrehm/ca579d5d9bb91e9ad0194d4a9b0fbb1e to your computer and use it in GitHub Desktop.
Expressão Regular para números de telefone fixo e celular do Brasil.
import re
p_celular = re.compile("^(0){0,1}([1-9]{2}){0,1}([7-8]|9[1-9])[0-9]{3}[0-9]{4}$")
print("Match no celular: ", re.search(p_celular, '022999860983'))
print("Não é um celular: ", re.search(p_celular, '01938735599'))
p_fixo = re.compile("^(0){0,1}([1-9]{2}){0,1}([2-6])[0-9]{3}[0-9]{4}$")
print("Match no fixo: ", re.search(p_fixo, '01938735599'))
print("Não é um fixo: ", re.search(p_fixo, '022999860983'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment