Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > Miscellaneous > Archive > Sunrise

Notices

 
 
Thread Tools Search this Thread
Old 05-02-2005, 09:12 PM   #1
csh
Junior Member
csh began at the beginning.
 
Posts: 3
Karma: 10
Join Date: May 2005
Device: Sony PEG-T665C
Question RegExp quandary

Trying to filter a quick document composed of URLs for articles at news.com.com I wanted to follow up on. For example:

<A HREF="http://news.com.com/Quote+of+the+day+Hedge+fund+guy+laughing+butt+off/2110-1010_3-5690203.html?tag=st_lh">Article</A>

which I wanted to modify to:

<A HREF="http://news.com.com/2110-1010_3-5690203.html?tag=st.util.print">Article</A>

Here's what I came up with for the filter script:
//Script for converting news.com.com articles to print version with referrer
//Setup for checking for an RE
var regexp = /news\.com\.com/.*\+.*/

document.onanchorlink = function(link) {
// Set referrer to original uri
link.referrer = link.uri;
//If URL contains match to regexp
if ( link.uri.match(regexp) != null) {
//Then
// Rewrite uri to point to printable version
var junk = link.uri.match(regexp)[0];
link.uri = link.uri.replace(junk, "/news.com.com/");
link.uri = link.uri.replace("tag=st_lh", "tag-st.util.print");
//Endif
};
};

Problem is I end up with a status of:
Error: Exception reading script file "null": missing name after . operator (<embedded> #3)

What is wrong with my script? (Where did I go wrong?)

Any patient help would be greatly appreciated.
csh is offline  
Old 05-03-2005, 12:47 PM   #2
coolacid
Junior Member
coolacid began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Apr 2005
Device: Visor
By no means am I good at this but try your regex as this:

var regexp = "/news\.com\.com/.*\\+.*/";

it went though fine, but i don't get the same links as you in my news so I can't test.
coolacid is offline  
Advert
Old 05-07-2005, 09:32 AM   #3
csh
Junior Member
csh began at the beginning.
 
Posts: 3
Karma: 10
Join Date: May 2005
Device: Sony PEG-T665C
Tried that too. (and tried .*\\\+.*) It seems to be a problem in escaping the meta-value of "+".

BTW, noticed an error in the last "replace" line. This:
link.uri = link.uri.replace("tag=st_lh", "tag-st.util.print");
should be:
link.uri = link.uri.replace("tag=st_lh", "tag=st.util.print");
csh is offline  
Old 05-07-2005, 09:45 AM   #4
Laurens
Jah Blessed
Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.
 
Laurens's Avatar
 
Posts: 1,295
Karma: 1373
Join Date: Apr 2003
Location: The Netherlands
Device: iPod Touch
You need to escape the forward slash after ".com"

Code:
var regexp = /news\.com\.com\/.*\+.*/
Laurens is offline  
Old 05-09-2005, 07:47 PM   #5
csh
Junior Member
csh began at the beginning.
 
Posts: 3
Karma: 10
Join Date: May 2005
Device: Sony PEG-T665C
Thanks, Laurens!

Didn't realize the leading and trailing '/' characters were bounding the RE. Now I see what was amiss. Explains why I was also ending up with the wrong number of '/' characters in the modified URL.
csh is offline  
Advert
 


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regexp and header/footer problems concern Calibre 0 02-07-2010 03:35 AM
iLiad Warranty Quandary wakawakawaka iRex Developer's Corner 5 10-06-2006 07:25 AM


All times are GMT -4. The time now is 04:38 PM.


MobileRead.com is a privately owned, operated and funded community.