简体   繁体   English

PHP 从 url 获取版本

[英]PHP Get version from url

How can I download the versions from the link?如何从链接下载版本? I tried to do it with regEx but it didn't work as I wanted.我试图用 regEx 来做,但它没有按我的意愿工作。

I wish it would work like this (Where I gave NULL, there is nothing to choose from)我希望它能像这样工作(我给了 NULL,没有什么可以选择的)

https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js > 1.11.2
https://ajax.googleapis.com/ajax/libs/jquery/v1.11.2/jquery.min.js > 1.11.2
https://ajax.googleapis.com/ajax/libs/jquery/version-1.11.2/jquery.min.js > 1.11.2
https://ajax.googleapis.com/ajax/libs/jquery/1-11-2/jquery.min.js > NULL
https://ajax.googleapis.com/ajax/libs/jquery/1112/jquery.min.js > NULL
https://www.google.com/recaptcha/api.js?render=6LdBsjgVaoTJ8rC-Npzz16bnAE > NULL

My regEx: /([0-9]+\.?)+/我的正则表达式:/( /([0-9]+\.?)+/ .?)+/

Thank you in advance for your help:)预先感谢您的帮助:)

You can use您可以使用

\/(?:v(?:ersion)?-?)?\K\d+(?:\.\d+)+

See the regex demo .请参阅正则表达式演示 NOTE: if you want to make sure after the version number there is a / or end of string, add a (?![^\/]) lookahead at the end of the pattern, \/(?:v(?:ersion)?-?)?\K\d+(?:\.\d+)+(?![^\/]) (see this regex demo ).注意:如果要确保版本号后面有/或字符串结尾,请在模式末尾添加(?![^\/])前瞻, \/(?:v(?:ersion)?-?)?\K\d+(?:\.\d+)+(?![^\/]) (参见这个正则表达式演示)。

Details :详情

  • \/ - a / char \/ - 一个/字符
  • (?:v(?:ersion)?-?)? - an optional sequence of a v and then an optional ersion and then an optional - char - \K - omit the matched text - 一个v的可选序列,然后是一个可选的ersion ,然后是一个可选的- char - \K - 省略匹配的文本
  • \d+(?:\.\d+)+ - match and consumer one or more digits and then one or more sequences of a dot and one or more digits. \d+(?:\.\d+)+ - 匹配并使用一个或多个数字,然后是一个或多个点序列和一个或多个数字。

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

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