unexpected end of regular expression

后端 未结 2 1402
旧巷少年郎
旧巷少年郎 2021-01-23 18:45

I want to get only the file name with extension from the path:

C:\\\\Users\\\\anandada\\\\workspace\\\\MyTestProject\\\\         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-23 19:28

    It is because you don't use a raw string. The double backslash is interpreted as an escape for the closing square bracket. You need to write:

    fileName = re.match(r"[^\\]*.c$", fileName)
    

    with the raw string format \\ is seen as a literal backslash as expected.

提交回复
热议问题