且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

解析字符串以提取URL或文件夹路径

更新时间:2023-01-15 16:30:51

U可以使用:

(?<type>[^ ]+?:)(?<path>//[^ ]*|\\.+\\[^ ]*)

每个结果将为您提供2组

that will give you 2 groups on each result

类型:"http:"

路径://www.thewebsite.com/NewStuff

类型:"J:"

路径:\Downloads\NewStuff

超出字符串

我将文件放在服务器上的 http://www.thewebsite.com/NewStuff ,也可以通过您的网站访问它们 本地网络驱动器位于J:\ Downloads \ NewStuff"

"I placed the files on the server at http://www.thewebsite.com/NewStuff, they can also be reached on your local network drives at J:\Downloads\NewStuff"

您可以使用类型"组来查看类型是否为http:并对此进行操作.

you can use the "type" group to see if the type is http:or not and set action on that.

编辑

或如果您确定文件路径中没有空格,请在下面使用正则表达式:

or use regex below if you are sure there is no whitespace in your filepath :

(?<type>[^ ]+?:)(?<path>//[^ ]*|\\[^ ]*)