// A sample class
class Human {
private int age = 0;
public void birthday() {
age++;
print('Happy Birthday!');
}
}
# coding:utf8
import re
def chars_test():
s = "13977889988"
p = r"\b1\d\d\d\d\d\d\d\d\d\d\b"
rs = re.match(p, s)
if rs != None:
print rs.group()
else:
print "no matched"
def limit_chars_test():
# 匹配手机号码
# s = "13977889988"
# p = r"\b1\d{10}\b"
# rs = re.match(p, s)
# 找出所有的三位数
# s = "100 88 9 112 9998 197 9876 77"
# p = r"\b\d{3}\b"
# print re.findall(p, s)
# 找出长度为4-5的单词
s = "abc hello defg world higkli"
p = r"\b\w{4,5}\b"
print re.findall(p, s)
# if rs != None:
# print rs.group()
# else:
# print "no matched"
def fanyi_chars_test():
# s = "hello 123 {world} world [456] "
# p1 = r"\b\S+\b"
# print re.findall(p1, s)
s = "012 3456 789 1011 999"
p = r"\b[^0]\d{2}\b"
print re.findall(p, s)
def group_test():
s = "<html><head>This is regex</head></html>"
p = r"<(?P<html_tag>\w+)><(?P<head_tag>\w+)>([\w\s]*)</(?P=head_tag)></(?P=html_tag)>"
rs = re.match(p, s)
if rs != None:
print rs.groups()
else :
print "no matched"
def test():
s = "adf Bdc A45 e87 c09"
p = r"[a-z]\w\w"
print re.findall(p, s)
def tx_test():
s = "MaQian HuNan 168-8877-7788"
p = r"(.+?)(\d+-\d+-\d+)"
rs = re.match(p, s)
if rs == None:
print "no matched"
else:
print rs.group(1)
print rs.group(2)
if __name__ == "__main__":
# chars_test()
# limit_chars_test()
# fanyi_chars_test()
# group_test()
# test()
tx_test()