Regular expression to match start of filename and filename extension

后端 未结 8 860
离开以前
离开以前 2020-12-08 15:35

What is the regular expression to match strings (in this case, file names) that start with \'Run\' and have a filename extension of \'.py\'?

The regular expression s

8条回答
  •  庸人自扰
    2020-12-08 16:24

    /^Run.*\.py$/
    

    Or, in python specifically:

    import re
    re.match(r"^Run.*\.py$", stringtocheck)
    

    This will match "Runfoobar.py", but not "runfoobar.PY". To make it case insensitive, instead use:

    re.match(r"^Run.*\.py$", stringtocheck, re.I)
    

提交回复
热议问题