正则表达式可匹配任何URL参数值(Perl语法) [英] Regular Expression to match on any URL parameter value (Perl syntax)
问题描述
我正在努力寻找一种模式,该模式将允许我选择URL字符串的Parameter = Value元素的值部分.我希望它足够通用,可以用任何术语替换参数"并检索其值.
I am struggling to find a pattern that will allow me to select the value portion of a Parameter=Value element of a URL string. I would like it to be generic enough that I could replace the 'Parameter' with any term and retrieve its value.
例如,如果URL字符串是(始终遵循此通用格式):
For example, if the URL string is (it always follows this general form):
' http://www.mysite.com /home.aspx?userid=53&transaction=2&viewport=属性'
我需要能够获得用户ID或交易或视口的价值部分,或有选择地获取价值.
I need to be able to the get value portion of userid or transaction or viewport, or whatever selectively.
最好像添加一个参数名称一样容易,并且它与在&之后跟随其=的传递相匹配.我尝试制作通用的匹配字符串...很糟糕.
Preferably it would be as easy as adding a parameter name and it matching eveything that follows its = to the &. My attempts to make a general purpose match string ... suck.
我不能使用javascript函数或其他任何东西,它必须像perl一样的正则表达式匹配 (如果您感到好奇,可以将其与Apache JMeter一起使用).
I cannot use a javascript function or anything, it has to be perl-like regex matching (This is for use with Apache JMeter if you are curious).
我在regex上很烂:-/在此先感谢您的帮助.
I suck at regex :-/ Thanks in advance for any help.
推荐答案
如果必须是正则表达式,
In case it has to be a regex,
/userid=([^&]*)/
这篇关于正则表达式可匹配任何URL参数值(Perl语法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!