正則表達式(Regular)

參考資料

自製regular測試程式

import re
 
def regularTest(pattren = None,org = None,*args):
    """
    pattren,org,((type:str)group items)...
    """
    if not pattren and not org and not args:#判斷參數是否有輸入
        raise ValueError,'you have to input'
 
    ma = re.search(pattren,org)
    if ma:
        print "---------match---------------"
        print ma.group()#印出符合的結果
        if len(args) > 0:
            print "-----------group items------------"
            for arg in args:
                    #印出(?P<name>exp)匹配exp,並捕獲文本到名稱為name的組裡
                print ma.group(arg)
                print "   --   --   --   --   --   --"
            print "----------------------------------"
        else:
            raise ValueError,'args error'
    else:
        raise ValueError,'input not match'