![]() |
#1 |
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24
Karma: 2128
Join Date: Dec 2002
|
Using Wildcard in uri.replace?
Is it possible to use a wildcard in a uri.replace call in a script? It doesn't seem to be working for me in this case so I'm guessing not, but maybe I'm just using it incorrectly.
I'm trying to make a change on the Link URL in the RSS (http://www.onmilwaukee.com/rss/rss.xml) from this: http://onmilwaukee.com/music/articles/gigs1105.html to the print version this: http://onmilwaukee.com/articles/print/gigs1105.html Problem is the first sub dir is always changing, so in this example it is "/music/articles/" needs to change to "/articles/print/" it could also be "/market/articles/" or "/bars/articles/" Bascically it's the first thing after the ./com/*/articles/ that I need to change. So right now I'm trying this: document.onanchorlink = function(link) { // Set referrer to original uri link.referrer = link.uri; // Rewrite uri to point to printable version link.uri = link.uri.replace("onmilwaukee.com/*/articles/", "onmilwaukee.com/articles/print/"); }; With no luck. If I need to set that first virtual directory (/music/" as a variable, to trap it, I'm not sure how to do that. Sorry for the obviously script-newbee question, but I'm just now starting to learn this a (very) little. Any suggestions? |
![]() |
![]() |
#2 |
Jah Blessed
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,295
Karma: 1373
Join Date: Apr 2003
Location: The Netherlands
Device: iPod Touch
|
Another approach would be to extract the filename and append that to the base "printable" URI:
Code:
document.onanchorlink = function(link) { link.referrer = link.uri; var filename = link.uri.substring(link.uri.lastIndexOf('/')); link.uri = "http://onmilwaukee.com/articles/print" + filename; }; |
![]() |
Advert | |
|
![]() |
#3 |
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24
Karma: 2128
Join Date: Dec 2002
|
Yeah, I was trying to figure out a way to do that as well. Wasn't familiar with the "lastIndexOf()". That is similar to another one I'm looking at, AnandTech. The Story ID is the last number of the URI, but it isn't right after the last /. Can I use another char maybe, like the "?"
So the story URI is: http://www.anandtech.com/cpuchipsets...oc.aspx?i=2598 and to grab the last "i=2598" to turn it into: http://www.anandtech.com/printarticle.aspx?i=2598 should be something like this?: document.onanchorlink = function(link) { link.referrer = link.uri; var filename = link.uri.substring(link.uri.lastIndexOf('?')); link.uri = "http://www.anandtech.com/printarticle.aspx?" + filename; }; Or am I not grasping the concept of this lastIndexOf call? |
![]() |
![]() |
#4 |
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24
Karma: 2128
Join Date: Dec 2002
|
Also, Laurens, you said "another approach" does that mean that the "*" in the replace should work?
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Search and replace in 0.2.0 | paulpeer | Sigil | 7 | 03-13-2010 11:59 AM |
Why no search and replace? | charleski | Sigil | 10 | 11-24-2009 04:13 PM |
How do I replace a book? | emellaich | Calibre | 3 | 07-15-2009 12:54 PM |
What will you replace your Kindle with. | pilotbob | Which one should I buy? | 33 | 03-16-2009 11:26 AM |
Did you replace your font? | TadW | Sony Reader | 2 | 10-03-2007 01:32 PM |