【发布时间】:2017-05-13 06:49:15
【问题描述】:
我有一个包含一堆随机 URL 的文件:
https://google.com
http://fakesite.net/php?id=2
https://example.com/
http://anotherexample.com/pho?admin=2
如何使用正则表达式验证 URL 是否包含 GET 参数而不是 POST?
【问题讨论】:
我有一个包含一堆随机 URL 的文件:
https://google.com
http://fakesite.net/php?id=2
https://example.com/
http://anotherexample.com/pho?admin=2
如何使用正则表达式验证 URL 是否包含 GET 参数而不是 POST?
【问题讨论】:
你的意思是它是否有查询参数?
require 'uri'
if URI('http://fakesite.net/php').query
...
end
如果您坚持使用正则表达式,请使用此
match = URI.regexp.match('http://fakesite.net/php?id=2')
if match[8]
...
end
你可以打印正则表达式
puts URI.regexp
太麻烦了,你最好只使用URI 类。
【讨论】:
Using a regular expression
match[8] 部分有什么作用?