PHP 从 url 获取版本
PHP Get version from url
如何从 link 下载版本?我试着用正则表达式来做,但它没有像我想要的那样工作。
我希望它能像这样工作(我给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
我的正则表达式:/([0-9]+\.?)+/
提前感谢您的帮助:)
您可以使用
\/(?:v(?:ersion)?-?)?\K\d+(?:\.\d+)+
参见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)?-?)?
- v
的可选序列,然后是可选的 ersion
,然后是可选的 -
字符
- \K
- 省略匹配的文本
\d+(?:\.\d+)+
- 匹配并使用一个或多个数字,然后是一个或多个点序列和一个或多个数字。
如何从 link 下载版本?我试着用正则表达式来做,但它没有像我想要的那样工作。
我希望它能像这样工作(我给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
我的正则表达式:/([0-9]+\.?)+/
提前感谢您的帮助:)
您可以使用
\/(?:v(?:ersion)?-?)?\K\d+(?:\.\d+)+
参见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)?-?)?
-v
的可选序列,然后是可选的ersion
,然后是可选的-
字符 -\K
- 省略匹配的文本\d+(?:\.\d+)+
- 匹配并使用一个或多个数字,然后是一个或多个点序列和一个或多个数字。