rodrigosantosbr

Brasilian Cep Regex

Jan 15th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!

Site:
https://regex101.com/
https://www.jdoodle.com/python3-programming-online
https://playcode.io/online-javascript-editor


Expression:

^\d{5}\-\d{3}$
60011-110
60450360
oi

Javascript

var re = /^\d{5}\-\d{3}$/;
var term1 = "00.059.191/0001-67";
var term2 = "60011-110";
var term3 = "60011110";

if (re.exec(term1)) {
    console.log("term1 Valid");
}
else {
    console.log("term1 Invalid");
}

if (re.exec(term2)) {
    console.log("term2 Valid");
}
else {
    console.log("term2 Invalid");
}

if (re.exec(term3)) {
    console.log("term3 Valid");
}
else {
    console.log("term3 Invalid");
}

python

import re
patt = r'^\d{5}\-\d{3}$'
term1 = '60011-110'
match1 = re.search(patt,term1)
term2 = '60450360'
match2 = re.search(patt,term2)

if match1:
    print("Valid: {}".format(match1.group()))
else:
    print("Invalid: {}".format(term1))

if match2:
    print("Valid: {}".format(match2.group()))
else:
    print("Invalid: {}".format(term2))
Add Comment
Please, Sign In to add comment