200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > python正则表达式匹配包含或者不包含字符串的方法

python正则表达式匹配包含或者不包含字符串的方法

时间:2018-10-31 14:36:54

相关推荐

python正则表达式匹配包含或者不包含字符串的方法

记录下正则匹配包含或者不包含字符串的表达式

import timeimport refindStr = 'setAttr ".uvst[0].uvsn" -type "string" "UVChannel_1";'#匹配不包含"UVChannel_1"的字符串, 表达式为"\"(?!UVChannel).*\";$", 注意文本中的引号需要转义pattern = pile(r'setAttr.\"\.uvst\[0]\.uvsn\".-type.\"string\".\"(?!map1).*\";$') pattern1 = pile(r'setAttr.\"\.uvst\[0]\.uvsn\".-type.\"string\".\"map1\";$')pattern2 = pile(r'setAttr \"\.uvst\[0]\.uvsn\" -type \"string\" \"UVChannel.*\";$')pattern3 = pile(r'setAttr \"\.uvst\[0]\.uvsn\" -type \"string\" \"(?!UVChannel).*\";$')def main():start = time.process_time()with open('heiYinPMHQZN01_all_render.ma', 'r') as fw:data = fw.readlines()for each in data:ret = pattern1.findall(each)if ret:print(each)end = time.process_time()print('Running time: %s Seconds' % (end - start))if __name__ == '__main__':main()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。