python3.7 匹配淘口令

# utf-8
import re


def get_tao_kou_ling(text: str) -> str:
    pattern = "؋‎฿₿¢₡₵$₫֏€₲₾₴₭₺₼₥₦₱£﷼‎៛₽₨௹₹৲৳૱₪₸₮₩¥₳₠₢₯₣₤₶₧₰₷"
    pattern = "([" + pattern + "])" + "(\\w+)\\1"
    result = re.compile(pattern).findall(text)
    try:
        result = result[0][0] + result[0][1] + result[0][0]  # 取匹配到的第一个
    except IndexError:
        result = ""
    return result
    pass


if __name__ == '__main__':
    string = "复植这行话₴N1PCasks₴转移至τаo宝аρρ【旅行拖鞋便携折叠人字拖情侣夏天海边沙滩鞋男女旅游休闲户外凉鞋】;或https://m.tb.cn/ " \
             "點ゞ撃°鏈バ接,再选择瀏覽嘂..咑№亓 "

    print('匹配结果:', get_tao_kou_ling(string))
    pass

结果:

匹配结果: ₴N1PCasks₴

Process finished with exit code 0
 

你可能感兴趣的:(练习)