Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
Old 12-21-2011, 01:05 PM   #1
scissors
Addict
scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.
 
Posts: 241
Karma: 1001369
Join Date: Sep 2010
Device: prs300, kindle keyboard 3g
"preprocess_regexps with special character '

I need to get rid of the 2 characters \' and replace with just '

trouble is using preprocess_regexps fails due to the '
I did a search but came up short - i think from one thread maybe hex code of the character has to be used...

can someone give the correct syntax?
scissors is offline   Reply With Quote
Old 12-21-2011, 01:20 PM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,791
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by scissors View Post
I need to get rid of the 2 characters \' and replace with just '

trouble is using preprocess_regexps fails due to the '
I did a search but came up short - i think from one thread maybe hex code of the character has to be used...

can someone give the correct syntax?
escape (the escaped)
\\\'
theducks is offline   Reply With Quote
Old 12-21-2011, 03:20 PM   #3
scissors
Addict
scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.
 
Posts: 241
Karma: 1001369
Join Date: Sep 2010
Device: prs300, kindle keyboard 3g
Quote:
Originally Posted by theducks View Post
escape (the escaped)
\\\'
I tried that in the following

preprocess_regexps = [
(re.compile(r'\\\'', re.IGNORECASE | re.DOTALL), lambda match: '`')]

I used ` as the replacement because ''' fails.

It didn't work.

Here is an example of text i'm trying to clean up.


Lana is one of 2011\'s biggest success stories. The gorgeous songstress found fame on the internet with her songs \'Video Games\' and \'Blue Jeans\'. Since then she has been everywhere, even singing for the fash pack at the Mulberry pool party in LA. With the soon to be released \'Born To Die\' we will all wonder how we ever coped without her slick vocals. Watch out 2012, Lana is coming!
scissors is offline   Reply With Quote
Old 12-21-2011, 03:29 PM   #4
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,791
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by scissors View Post
I tried that in the following

preprocess_regexps = [
(re.compile(r'\\\'', re.IGNORECASE | re.DOTALL), lambda match: '`')]

I used ` as the replacement because ''' fails.

It didn't work.

Here is an example of text i'm trying to clean up.


Lana is one of 2011\'s biggest success stories. The gorgeous songstress found fame on the internet with her songs \'Video Games\' and \'Blue Jeans\'. Since then she has been everywhere, even singing for the fash pack at the Mulberry pool party in LA. With the soon to be released \'Born To Die\' we will all wonder how we ever coped without her slick vocals. Watch out 2012, Lana is coming!
I just pasted the above into a new Sigil document.
My regex search \\\' found all and a simple ' was the replace

Go Sigil
IMHO fix it outside, it is so easy that way
theducks is offline   Reply With Quote
Old 12-21-2011, 03:33 PM   #5
scissors
Addict
scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.
 
Posts: 241
Karma: 1001369
Join Date: Sep 2010
Device: prs300, kindle keyboard 3g
Quote:
Originally Posted by theducks View Post
I just pasted the above into a new Sigil document.
My regex search \\\' found all and a simple ' was the replace

Go Sigil
IMHO fix it outside, it is so easy that way
Sorry, I never made myself clear. It's in a news recipe.

I just noticed everything after '\\\'' is light brown - which means it's being treated as part of the string (I guess due to double '')
scissors is offline   Reply With Quote
Old 12-21-2011, 03:37 PM   #6
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,791
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
@sissors, should I put on my Mod hat and move this thread to Recipies?
theducks is offline   Reply With Quote
Old 12-21-2011, 03:43 PM   #7
scissors
Addict
scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.
 
Posts: 241
Karma: 1001369
Join Date: Sep 2010
Device: prs300, kindle keyboard 3g
I was gonna put it in recipes, but then i thought it was more a general syntax query.

Feel free to move it.
scissors is offline   Reply With Quote
Old 12-21-2011, 03:56 PM   #8
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,791
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Moderator Notice
Moved
theducks is offline   Reply With Quote
Old 12-21-2011, 05:24 PM   #9
Barty
doofus
Barty ought to be getting tired of karma fortunes by now.Barty ought to be getting tired of karma fortunes by now.Barty ought to be getting tired of karma fortunes by now.Barty ought to be getting tired of karma fortunes by now.Barty ought to be getting tired of karma fortunes by now.Barty ought to be getting tired of karma fortunes by now.Barty ought to be getting tired of karma fortunes by now.Barty ought to be getting tired of karma fortunes by now.Barty ought to be getting tired of karma fortunes by now.Barty ought to be getting tired of karma fortunes by now.Barty ought to be getting tired of karma fortunes by now.
 
Barty's Avatar
 
Posts: 2,520
Karma: 13036221
Join Date: Sep 2010
Device: Kobo Libra 2, Kindle Voyage
Don't quote me on this (haha), but try

Code:
preprocess_regexps = [
 (re.compile(r"\\'", re.IGNORECASE | re.DOTALL), lambda match: "'")]
Barty is offline   Reply With Quote
Old 12-22-2011, 10:07 AM   #10
scissors
Addict
scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.
 
Posts: 241
Karma: 1001369
Join Date: Sep 2010
Device: prs300, kindle keyboard 3g
Quote:
Originally Posted by Barty View Post
Don't quote me on this (haha), but try

Code:
preprocess_regexps = [
 (re.compile(r"\\'", re.IGNORECASE | re.DOTALL), lambda match: "'")]
hi there.

You'd think that would work...

here's a piece of the web page source - i can't see why that wouldn't work

"caption": "<p>This American actress is setting tinseltown alight with her pretty looks and impressive acting ability. She rose to fame for her role in \'True Grit\' and was even nominated for an Academy Award and a BAFTA. The teen star is creating quite a splash in the fashion arena too, just recently her Miu Miu advert got banned for being \'irresponsible\'. Eek! We predict front row action at February\'s international fashion weeks</p>"
scissors is offline   Reply With Quote
Old 12-27-2011, 11:02 AM   #11
pietvo
Reader
pietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notes
 
pietvo's Avatar
 
Posts: 519
Karma: 24612
Join Date: Aug 2009
Location: Utrecht, NL
Device: Kobo Aura 2, iPhone, iPad
Please note that that source code is part of Javascript on the website. So the question is what are you doing with the result of the substitution?

The substitution itself should work:
Quote:
>>> import re
>>> regex = re.compile(r"\\'", re.IGNORECASE | re.DOTALL)
>>> text = r"""Lana is one of 2011\'s biggest success stories. The gorgeous songstress found fame on the internet with her songs \'Video Games\' and \'Blue Jeans\'. Since then she has been everywhere, even singing for the fash pack at the Mulberry pool party in LA. With the soon to be released \'Born To Die\' we will all wonder how we ever coped without her slick vocals. Watch out 2012, Lana is coming!"""
>>> print text
Lana is one of 2011\'s biggest success stories. The gorgeous songstress found fame on the internet with her songs \'Video Games\' and \'Blue Jeans\'. Since then she has been everywhere, even singing for the fash pack at the Mulberry pool party in LA. With the soon to be released \'Born To Die\' we will all wonder how we ever coped without her slick vocals. Watch out 2012, Lana is coming!
>>> print regex.sub(lambda match: "'", text)
Lana is one of 2011's biggest success stories. The gorgeous songstress found fame on the internet with her songs 'Video Games' and 'Blue Jeans'. Since then she has been everywhere, even singing for the fash pack at the Mulberry pool party in LA. With the soon to be released 'Born To Die' we will all wonder how we ever coped without her slick vocals. Watch out 2012, Lana is coming!
pietvo is offline   Reply With Quote
Old 12-28-2011, 03:56 AM   #12
scissors
Addict
scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.
 
Posts: 241
Karma: 1001369
Join Date: Sep 2010
Device: prs300, kindle keyboard 3g
Quote:
Originally Posted by pietvo View Post
Please note that that source code is part of Javascript on the website. So the question is what are you doing with the result of the substitution?

The substitution itself should work:
Sorry, but I couldn't really understand what you are saying there. I take it you are saying the text I'm trying to sought is actually part of the sites javascript - so i've removed the "remove javascript" command.

In the meantime it looks like it was only that one article that was done in that way....
scissors is offline   Reply With Quote
Old 12-28-2011, 03:10 PM   #13
pietvo
Reader
pietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notes
 
pietvo's Avatar
 
Posts: 519
Karma: 24612
Join Date: Aug 2009
Location: Utrecht, NL
Device: Kobo Aura 2, iPhone, iPad
Quote:
Originally Posted by scissors View Post
Sorry, but I couldn't really understand what you are saying there. I take it you are saying the text I'm trying to sought is actually part of the sites javascript
Yes, that's what I meant.
pietvo is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
"preprocess_regexps = [(re.compile..." bugged? scissors Recipes 8 11-02-2011 03:56 PM
special character in metadata search happyuser Calibre 1 10-19-2011 11:33 AM
Special Character searches ElMiko Calibre 2 09-05-2011 10:52 PM
-iBookstore- "His Niji" Realistic Character based Story-Telling Rollzlx Self-Promotions by Authors and Publishers 11 10-31-2010 03:23 PM
"ascii' codec can't encode character" bug ? zelda_pinwheel Calibre 2 12-21-2008 08:12 PM


All times are GMT -4. The time now is 02:40 AM.


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