Trying to check the correctness of steam trade offer link which looks like

https://steamcommunity.com/tradeoffer/new/?partner=200396688&token=XSvAH09r 

(in this case, this is my link) Check for js and php, for js I try this:

 var expr = new RegExp(/http(?:s)://steamcommunity.com/tradeoffer/new/?partner=([0-9]+)&token=([a-zA-Z]+)/; expr.test("https://steamcommunity.com/tradeoffer/new/?partner=200396688&token=XSvAH09r"); 

but writes

 SyntaxError: nothing to repeat 

Ps who is not difficult, help to make a regular expression in php, I have with them tight

  • one
    I think you don't have a terminating parenthesis in the expression new RegExp (... - cheops
  • added the same thing .. - Red Woolf
  • one
    Escaping special characters is not enough yet, added the answer below. - cheops

1 answer 1

You should fix the regular expression as follows

  var expr = /http(?:s):\/\/steamcommunity.com\/tradeoffer\/new\/\?partner=([0-9]+)&token=([a-zA-Z0-9]+)/; expr.test("https://steamcommunity.com/tradeoffer/new/?partner=200396688&token=XSvAH09r"); 

In PHP

 <?php $pattern = "/^http[s]*:\/\/steamcommunity.com\/tradeoffer\/new\/\?partner=([0-9]+)&token=([a-zA-Z0-9]+)$/"; $url = "https://steamcommunity.com/tradeoffer/new/?partner=200396688&token=XSvAH09r"; if(preg_match($pattern, $url)) echo "Валиден"; 
  • Thanks for php too)) - Red Woolf