[英]Regex Match Specific URL String
I have structure of URL like this: https://steamcommunity.com/tradeoffer/new/?partner=12a3456asdf789&token=12345Dasdew678
我有这样的URL结构: https://steamcommunity.com/tradeoffer/new/?partner=12a3456asdf789&token=12345Dasdew678
: https://steamcommunity.com/tradeoffer/new/?partner=12a3456asdf789&token=12345Dasdew678
The two parameters of the URL, partner
and token
will have dynamic values which can contain alphanumeric characters only. URL的两个参数( partner
和token
将具有动态值,该值只能包含字母数字字符。
I would like to know if the format of the URL meets my requirements 我想知道网址的格式是否符合我的要求
if($URLisFormattedProperly) {
return true;
} else {
return false;
}
How should I do this? 我应该怎么做?
Here you go, regex based on your existing URL 在这里,根据您现有的URL进行正则表达式
preg_match('/https\:\/\/steamcommunity\.com\/tradeoffer\/new\/\?partner=([a-zA-Z0-9]+)&token=([a-zA-Z0-9]+)/', $url, $matches);
if(count($matches)>0)
{
// this meets your criteria
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.