java regular expression to match file path

后端 未结 8 1849
自闭症患者
自闭症患者 2020-12-03 18:40

I was trying out to create a regular expression to match file path in java like

C:\\abc\\def\\ghi\\abc.txt

I tried this ([

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 19:19

    Use this regex:

    "([a-zA-Z]:)?(\\\\[a-zA-Z0-9._-]+)+\\\\?";
    

    I added two modifications: you forgot to add . for matching the file name abc.txt and backslash escaping (\\) was also needed.

提交回复
热议问题