java regular expression to match file path

后端 未结 8 1884
自闭症患者
自闭症患者 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:07

    Just saying, one should replace the . in

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

    with \\.

    . is meant for any character in a regular expression (Java style), while
    \. is specifically meant for . character, and we need to escape the backslash

提交回复
热议问题