Python: How to use RegEx in an if statement?

后端 未结 5 2078
鱼传尺愫
鱼传尺愫 2020-12-25 10:06

I have the following code which looks through the files in one directory and copies files that contain a certain string into another directory, but I am trying to use Regula

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-25 10:23

    Regex's shouldn't really be used in this fashion - unless you want something more complicated than what you're trying to do - for instance, you could just normalise your content string and comparision string to be:

    if 'facebook.com' in content.lower():
        shutil.copy(x, "C:/Users/David/Desktop/Test/MyFiles2")
    

提交回复
热议问题