Validate URL query string with regex

前端 未结 6 2042
南笙
南笙 2020-12-06 03:00

I\'m trying to validate a query string with regex. Note that I\'m not trying to match out the values, but validate its syntax. I\'m doing this to practice regex, so I\'d app

6条回答
  •  自闭症患者
    2020-12-06 03:30

    I agree with Andy Lester, but a possible regex solution is

    #^\?([\w-]+=[\w-]*(&[\w-]+=[\w-]*))?$#
    

    which is very much like what you posted.

    I haven't tested it and you didn't say what language you're using so it may need a little tweaking.

提交回复
热议问题