简体   繁体   中英

Fixing the URL with Coldfusion regex

I need to edit some URL data, but i am facing some issue, the url is coming as:

<cfset myurl = "http:/example.com/0.asp?rpttype=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&companyQ=195&companyQ=105&companyQ=136&companyQ=126&productQ=1072&productQ=1042&productQ=1043stateQ=&sortBy=1&sortOrder=1">

<cfset reURL = queryStringDeleteVar("companyQ",myurl)>
<cfset reURL = queryStringDeleteVar("productQ",reURL)>
<cfset reURL = reURL & "&companyQ=">
<cfset listData = ''>
<cfloop list="#getCompanyID#" index="k">
    <cfset listData = ListChangeDelims(ListPrepend(listData,"%27+or+q2.comp+%3D%27=" & k),'',',')>
</cfloop>
<cfdump var="#reURL##listData#" label="URL Rewritten">

rewriting as:

http://example.com/0.asp?rpttype=298&stateQ=&sortBy=1&sortOrder=1&companyQ=%27+or+q2.comp+%3D%27=186%27+or+q2.comp+%3D%27=176%27+or+q2.comp+%3D%27=150%27+or+q2.comp+%3D%27=148 

but it needs to be like this

http://example.com/0.asp?rpttype=298&stateQ=&sortBy=1&sortOrder=1&companyQ=186%27+or+q2.comp+%3D%27=176%27+or+q2.comp+%3D%27=150%27+or+q2.comp+%3D%27=148 

i am missing something,

please guide

this

companyQ=%27+or+q2.comp+%3D%27=186

needs to like this for the first one only

companyQ=186

only the first one, remaining will stay as it is:

the value 186 is dynamic

I think this should just help you.

<cfset myurl = "http:/example.com/0.asp?rpttype=298&companyQ=148&companyQ=150&companyQ=176&companyQ=186&companyQ=195&companyQ=105&companyQ=136&companyQ=126&productQ=1072&productQ=1042&productQ=1043stateQ=&sortBy=1&sortOrder=1">
<cfset reURL = queryStringDeleteVar("companyQ",myurl)>
<cfset reURL = queryStringDeleteVar("productQ",reURL)>
<cfset reURL = reURL & "&companyQ=#listFirst(getCompanyID)#">
<cfset getCompanyID = listDeleteAt(getCompanyID,1)>
<cfset listData = ''>
<cfloop list="#getCompanyID#" index="k">
    <cfset listData =ListPrepend(listData,"%27+or+q2.comp+%3D%27=" & k)>
</cfloop>
<cfset listData = listChangeDelims(listData,"") />
<cfdump var="#reURL##listData#" label="URL Rewritten">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM