Regex expressions help - query strings
Can anyone give me the regex to validate the URL with the query string with 2 parameters
http://www.example.com?pid=3&sid=4
I want to validate if the input matches the above URL with exact parameters, how do i write a regex for th开发者_运维知识库is
Thanks in advance!
^(http://)?(www\.)?[0-9A-z]+\.com\?pid=(?<pid>\d+)&sid=(?<sid>\d+)$
^https?://(www\.)?((?!-)[a-z0-9-]+(?<!-)\.)+\w{2,6}/\w+/(default\.aspx)?\?pid=\d+&sid=\d+$
Will match:
http://www.domain.tld/directory/?pid=123&sid=123
http://www.domain.tld/directory/default.aspx?pid=123&sid=123
http://www.sub-domain.domain.tld/directory/?pid=123&sid=123
http://www.sub-domain.domain.tld/directory/default.aspx?pid=123&sid=123
as well as URLs without www.
and URLs with https as protocol.
Assuming pid & sid are static.
pid=(.*)&sid=(.*)
精彩评论