代码高亮测试

// 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()





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值