Last active
June 12, 2019 11:59
-
-
Save joaopcnogueira/cc228778678cf7d3f79ef26e7b4e8722 to your computer and use it in GitHub Desktop.
CPF string to number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
my_string = "012.345.678-09" | |
digits_pattern = r"\d+" | |
digits = re.findall(digits_pattern, my_string) | |
number = int(''.join(digits)) | |
print(number) | |
# output: 1234567809 | |
############### | |
# another way # | |
############### | |
digits_pattern = r"[.-]" | |
digits = re.split(digits_pattern, my_string) | |
number = int(''.join(digits)) | |
print(number) | |
# output: 1234567809 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Function to decode CPF's in string format to number (int) format.