White scenery @showyou, hatena

If you have any comments, you may also send twitter @shsub or @showyou.

今日のお料理

無駄に長くて鬱陶しいので短縮させましょう。

reg = re.compile('http://\S+\s*')
regTag = re.compile('\[.*\]')
regTag2 = re.compile('\*.*\*')
regBrowsing = re.compile('(B|b)rowsing:.*')
regRT = re.compile("(RT|QT):.*")
regHashtag = re.compile("#\S+")
def RemoveCharacter(str):
    #余計な記号(http://とか、[hoge]とか)
    if reg.search(str):
        print_d2("http cut")
        str = reg.sub('',str)
        
    if regTag.search(str):
        print_d2("tag cut")
        str = regTag.sub('',str)
        
    if regTag2.search(str):
        print_d2("tag2 cut")
        str = regTag2.sub('',str)
        
    if regBrowsing.search(str):
        print_d2("browsing cut")
        str = regBrowsing.sub('',str)
        
    if regRT.search(str):
        print_d2("rt cut")     
        str = regRT.sub('',str)   
        
    if regHashtag.search(str):
        print_d2("hashtag cut")
        str = regHashtag.sub('',str)

    return str

理想

regs = [
    (re.compile('http://\S+\s*'), "http"),
    (re.compile('\[.*\]'), "tag"),
    (re.compile('\*.*\*'), "tag2"),
    (re.compile('(B|b)rowsing:.*'), "browse"),
    (re.compile("(RT|QT):.*"), "RT"),
    (re.compile("#\S+"), "hashtag")
]

def RemoveCharacter(str):
    #余計な記号(http://とか、[hoge]とか)
    for r in regs:
        if r[0].search(str):
            print_d2(r[1]+" cut")
            str = r[0].sub('',str)

必要なもの

  • デグレードチェックのためのテスト。noseあたりで書くか?

追記

hashtagの削除、"#\S"だと一文字しか判定されないので"#\S+"にした