Regex 从URL中提取数值

Regex 从URL中提取数值,regex,coldfusion,Regex,Coldfusion,我有下面的代码,我想提取特定URL的所有值,我尝试使用rereplacenocase,但没有帮助 http://example.com/1.asp?type=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&productQ=1072&productQ=1042&productQ=1043 我想在逗号分隔的值中提取公司q的所有数值,如何获取该值 像这样试过 <cfloop

我有下面的代码,我想提取特定URL的所有值,我尝试使用rereplacenocase,但没有帮助

http://example.com/1.asp?type=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&productQ=1072&productQ=1042&productQ=1043
我想在逗号分隔的值中提取
公司q
的所有数值,如何获取该值

像这样试过

<cfloop list="#myurl#" index="k">
    <cfset getcompanyID = ListAppend(k,'&')>
</cfloop>

当然会有更优雅的方式,而且肯定不止一种。我假设url不是实际的应用程序url,而是一个变量(可以更好地处理url范围)


当然会有更优雅的方式,而且肯定不止一种。我假设url不是实际的应用程序url,而是一个变量(可以更好地处理url范围)


当然会有更优雅的方式,而且肯定不止一种。我假设url不是实际的应用程序url,而是一个变量(可以更好地处理url范围)


当然会有更优雅的方式,而且肯定不止一种。我假设url不是实际的应用程序url,而是一个变量(可以更好地处理url范围)


这是解决您问题的另一种方法

<cfset myurl="http://example.com/1.asp?type=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&productQ=1072&productQ=1042&productQ=1043">
<cfset urlstring = listLast(myurl,"?")>
<cfset ids = rereplace(arrayToList(rematch("companyQ=[0-9]*", urlstring)),"companyQ=","","all")>
<cfdump var="#ids#">

这是解决您问题的另一种方法

<cfset myurl="http://example.com/1.asp?type=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&productQ=1072&productQ=1042&productQ=1043">
<cfset urlstring = listLast(myurl,"?")>
<cfset ids = rereplace(arrayToList(rematch("companyQ=[0-9]*", urlstring)),"companyQ=","","all")>
<cfdump var="#ids#">

这是解决您问题的另一种方法

<cfset myurl="http://example.com/1.asp?type=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&productQ=1072&productQ=1042&productQ=1043">
<cfset urlstring = listLast(myurl,"?")>
<cfset ids = rereplace(arrayToList(rematch("companyQ=[0-9]*", urlstring)),"companyQ=","","all")>
<cfdump var="#ids#">

这是解决您问题的另一种方法

<cfset myurl="http://example.com/1.asp?type=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&productQ=1072&productQ=1042&productQ=1043">
<cfset urlstring = listLast(myurl,"?")>
<cfset ids = rereplace(arrayToList(rematch("companyQ=[0-9]*", urlstring)),"companyQ=","","all")>
<cfdump var="#ids#">

您可以尝试以下方法(任何url参数名称的通用解决方案)。注意在
REMatchNoCase()
中使用regex单词边界
\b
,以防止捕获参数,如
acompanyQ

<cfset the_param_name = "companyQ" />
<cfset the_url = "http://example.com/1.asp?type=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&productQ=1072&productQ=1042&productQ=1043" />
<cfset the_match = REMatchNoCase("\b#the_param_name#=[^&]+", the_url) />
<cfset the_value_list = replaceNoCase(arrayToList(test), "#the_param_name#=", "", "all") />
<cfdump var="#the_value_list#" />

如果您想获得更多乐趣,可以改用Java正则表达式(使用lookback确保只获得正确的参数值):


您可以尝试以下方法(任何url参数名称的通用解决方案)。注意在
REMatchNoCase()
中使用regex单词边界
\b
,以防止捕获参数,如
acompanyQ

<cfset the_param_name = "companyQ" />
<cfset the_url = "http://example.com/1.asp?type=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&productQ=1072&productQ=1042&productQ=1043" />
<cfset the_match = REMatchNoCase("\b#the_param_name#=[^&]+", the_url) />
<cfset the_value_list = replaceNoCase(arrayToList(test), "#the_param_name#=", "", "all") />
<cfdump var="#the_value_list#" />

如果您想获得更多乐趣,可以改用Java正则表达式(使用lookback确保只获得正确的参数值):


您可以尝试以下方法(任何url参数名称的通用解决方案)。注意在
REMatchNoCase()
中使用regex单词边界
\b
,以防止捕获参数,如
acompanyQ

<cfset the_param_name = "companyQ" />
<cfset the_url = "http://example.com/1.asp?type=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&productQ=1072&productQ=1042&productQ=1043" />
<cfset the_match = REMatchNoCase("\b#the_param_name#=[^&]+", the_url) />
<cfset the_value_list = replaceNoCase(arrayToList(test), "#the_param_name#=", "", "all") />
<cfdump var="#the_value_list#" />

如果您想获得更多乐趣,可以改用Java正则表达式(使用lookback确保只获得正确的参数值):


您可以尝试以下方法(任何url参数名称的通用解决方案)。注意在
REMatchNoCase()
中使用regex单词边界
\b
,以防止捕获参数,如
acompanyQ

<cfset the_param_name = "companyQ" />
<cfset the_url = "http://example.com/1.asp?type=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&productQ=1072&productQ=1042&productQ=1043" />
<cfset the_match = REMatchNoCase("\b#the_param_name#=[^&]+", the_url) />
<cfset the_value_list = replaceNoCase(arrayToList(test), "#the_param_name#=", "", "all") />
<cfdump var="#the_value_list#" />

如果您想获得更多乐趣,可以改用Java正则表达式(使用lookback确保只获得正确的参数值):



您的意思是说您的CFML代码有一个包含该URL的字符串,您需要从该字符串中解析出值,还是说这是您请求的URL(即:用户已浏览到该URL),您希望将
companyQ
参数的所有值传递给请求?您使用的是哪个版本的ColdFusion?您的意思是您的CFML代码有一个包含该URL的字符串,您需要从该字符串中解析出值,还是该URL是您请求的URL(即:用户已浏览到该URL),并且您希望将
companyQ
参数的所有值传递给请求?您使用的是哪个版本的ColdFusion?您的意思是您的CFML代码有一个包含该URL的字符串,您需要从该字符串中解析出值,还是该URL是您请求的URL(即:用户已浏览到该URL),并且您希望将
companyQ
参数的所有值传递给请求?您使用的是哪个版本的ColdFusion?您的意思是您的CFML代码有一个包含该URL的字符串,您需要从该字符串中解析出值,还是该URL是您请求的URL(即:用户已浏览到该URL),并且您希望将
companyQ
参数的所有值传递给请求?您使用的是哪个版本的ColdFusion?