What is the most correct regular expression for a UNIX file path?

前端 未结 6 901
面向向阳花
面向向阳花 2020-12-03 05:39

What is the most correct regular expression (regex) for a UNIX file path?

For example, to detect something like this:

/usr/lib/libgccpp.so.1.0.2
         


        
6条回答
  •  长情又很酷
    2020-12-03 05:45

    I'm not sure how common a regex check for this is across systems, but most programming languages (especially the cross platform ones) provide a "file exists" check which will take this kind of thing into account

    Out of curiosity, where are these paths being input? Could you control that to a greater degress to the point where you won't have to check the individual pieces of the path? For example using a file chooser dialog?

提交回复
热议问题