简体   繁体   English

文件路径或路径的正则表达式或正则表达式可以是什么?

[英]What can be the regular expression or regex for a file path or path?

I am new to this.我是新来的。 Please can anyone tell me what can be the regular expression for file path or any path:谁能告诉我文件路径或任何路径的正则表达式是什么:

Ex => "C:\\\\Users\\\\1700000\\\\Downloads\\\\BackendApp\\\\WebApplication\\\\WebAPI_APPL\\\\Data\\\\1\\\\FirstFol\\\\SecondFodler\\\\MainFolder\\\\File.xlsx"例如 => "C:\\\\Users\\\\1700000\\\\Downloads\\\\BackendApp\\\\WebApplication\\\\WebAPI_APPL\\\\Data\\\\1\\\\FirstFol\\\\SecondFodler\\\\MainFolder\\\\File.xlsx"

or或者

"C:\\\\Users\\\\1700000\\\\Downloads\\\\BackendApp\\\\WebApplication\\\\WebAPI_APPL\\\\Data\\\\1\\\\FirstFol\\\\SecondFodler\\\\MainFolder"

File path or path can be small or big , it is not fixed.文件路径或路径可大可小,不固定。 Path should start with "C(any drive):\\" Please let me know what can I use also the expression should consider double backslash in it.路径应以“C(任何驱动器):\\”开头

This expressions didn't work该表达式无效

  1. @"^(?:[\w]\:|\\\\)(\\\\[a-z_\-\s0-9\.]+)+\.(txt|gif|pdf|doc|docx|xls|xlsx)$"
  2. @"^(?:[a-zA-Z]\:|\\\\\\\\[\w\.]+\\\\[\w.$]+)\\\\(?:[\w]+\\\\)*\w([\w.])+$"

Try this one:试试这个:

^(?:[\w]:|\\)([A-Za-z_\s0-9.-\\]+)\.(txt|gif|pdf|docx|doc|xlsx|xls)$

you could use https://regex101.com/ to try yours regex你可以使用https://regex101.com/来试试你的正则表达式

Here's one i've used in the past for unix based systems这是我过去用于基于 unix 的系统的一个

(\/)((\w|-|_|[0-9])*\/(\w|-|_|[0-9])*)+[^.*\.]

For windows it will be essentially the same + detecting drive letter:对于 windows 本质上是相同的+检测驱动器号:

([A-Z]{1}:)(\/)((\w|-|_|[0-9])*\/(\w|-|_|[0-9])*)+[^.*\.]*

With backslashes:带反斜杠:

([A-Z]{1}:)(\\\\)((\w|-|_|[0-9])*\\\\(\w|-|_|[0-9])*)+[^.*\.]*

When I used it I expected my strings to be paths only.当我使用它时,我希望我的字符串只是路径。 It may capture text after a path so it's not perfect.它可能会在路径后捕获文本,因此它并不完美。 But I hope this helps.但我希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM