mateuszji
mateuszji

Reputation: 67

Regex Match Specific URL String

I have structure of URL like this: 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.

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?

Upvotes: 0

Views: 192

Answers (1)

skrilled
skrilled

Reputation: 5371

Here you go, regex based on your existing 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
}

Upvotes: 1

Related Questions