House of Fusion
Home of the ColdFusion Community

Search regex

December 02, 2008

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
   1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31       

Search over 2,500 ColdFusion resources here  >>>      
Home /  Groups /  Regular Expressions (RegEx)

ISAPI Converting URL value

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Abigail Coker
08/04/2008 10:13 AM

I was wondering is anyone could help, Using Regex how do I go about converting e.g. http://127.0.0.1/imp/www/index.cfm?id=889 to http://127.0.0.1/imp/www/889.cfm The value 889 can be any number... Thanks Abigail

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
08/04/2008 10:23 AM

> Using Regex how do I go about converting e.g. > http://127.0.0.1/imp/www/index.cfm?id=889 to > http://127.0.0.1/imp/www/889.cfm > > The value 889 can be any number... > I'm not sure about the specifics of ISAPI Rewrite, but these should do what you want... Match: ([^?#]*/imp/www)/(\d+).cfm Replace: \1/index.cfm?id=\2 (Might need $1 and $2 instead of \1 and \2 in replace)

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Abigail Coker
08/04/2008 12:05 PM

----- Excess quoted text cut - see Original Post for more ----- Going by your example I tried the code below it threw an error but I stuck an extra # but doesn't seem to do anything....I've tried a some workarounds with joy. <cfset stringToWork = Rereplace("http://127.0.0.1/imp/www/index.cfm?id=889","([^?#]*/imp/www)/(\d+).cfm","\1/index.cfm?id=\2","ALL")> <cfoutput>#stringToWork#</cfoutput> This is what I had http://127.0.0.1/imp/www/index.cfm?id=889

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
08/04/2008 12:15 PM

----- Excess quoted text cut - see Original Post for more ----- Ah, what I had given you will work the other way round - converting from 889.cfm to index.cfm?id=889 Just to be clear, here are a couple of working examples for both directions... <cfset input = "http://127.0.0.1/imp/www/index.cfm?id=889"/> <cfset output = rereplace( input , "([^?##]*/imp/www)/index.cfm\?id=(\d+)" , "\1/\2.cfm" )/> <cfoutput>#input# -> #output#</cfoutput> <hr/> <cfset input = "http://127.0.0.1/imp/www/889.cfm"/> <cfset output = rereplace( input , "([^?##]*/imp/www)/(\d+).cfm" , "\1/index.cfm?id=\2" )/> <cfoutput>#input# -> #output#</cfoutput>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Abigail Coker
08/04/2008 12:25 PM

Thanks a lot Peter, both worked like a dream. Thanks, Abi

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Abigail Coker
08/05/2008 04:34 AM

HI abigail, i'm not sure, but i think you have this backwards. isapi_rewrite takes the incoming url & converts it to a physical url _before_ iis/cf/php etc gets ahold of it. my guess is that you really want to convert: http://127.0.0.1/imp/www/889 (note the lack of a ".cfm" which is not needed when doing this config) to: http://127.0.0.1/imp/www/index.cfm?id=889 the easiest way to do this is to simply anchor to the back of the string using the $ and look for numeric values using [0-9]+ so the regex would simply look like this: /([0-9]*)$/ then in the parsed output you would just do something like this: index.cfm?id=\1 all of your output code will just need to have the urls formatted to use the new 'clean' system. Hope this helps! -Chris Hi Chris, Thanks for your input, the 2 examples Peter gave actually worked, just out of interest I'll try your example and see what I get. Thanks, Abi -----------------------------------------------------------------------------------


<< Previous Thread Today's Threads Next Thread >>

Mailing Lists