View Single Post
Old 08-29-2010, 07:44 AM   #2
Adoby
Handy Elephant
Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.
 
Adoby's Avatar
 
Posts: 1,055
Karma: 3824376
Join Date: Dec 2009
Location: Southern Sweden, far out in the quiet woods
Device: Ubuntu Linux, Cybook Opus, Motorola Xoom with Mantano Premium
I will give you several answers:

Answer 1:
Just write a regular expression that match the header/footer.

Answer 2:
Learn how to write regular expressions, and then try Answer 1 above. It is a really fun and exciting skill to have: http://docs.python.org/library/re.html#re-syntax

Answer 3:
Try to ask on a online forum, and hope that someone can be bothered to answer you.

Answer 4:
Follow these directions.

I did a footer removal on a PDF. The footer looks like this:

Code:
_<br>
www.eboat.net                                              Page                                                           eboat.net<br>
1<br>
<hr>
The pattern to match this might be built using the following parts:

() surround a part to match. So we need () around it all.

The first part is easy:

(_<br>)

This match the first line. In order to skip ahead to the next line we match some whitespace. Tabs, spaces and newlines. A special code exists for this, namely \s. There may not be any whitespace, or a lot. A * after a pattern will make the pattern match from 0 to many times. So now we have:

(_<br>\s*)

The next few parts should now be obvious:

(_<br>\s*www.eboat.net\s*Page\s*eboat.net<br>\s*)

Next comes a page number. That can change so we match one or more digits instead. The code \d will match a digit. If we add a + it will match one or more digits:

(_<br>\s*www.eboat.net\s*Page\s*eboat.net<br>\s*\d +)

Just a few finishing touches, and we are done:

(_<br>\s*www.eboat.net\s*Page\s*eboat.net<br>\s*\d +\s*<br>\s*<hr>)

I don't actually remember all these codes. I look them up when I need them. But some I do remember. Write a few regular expressions, and it will become easier every time.

http://docs.python.org/library/re.html#re-syntax

Now it should be easy for you to write your own regular expression that match your examples.

One of them would be (have not tested, so it could be wrong):

(<b>Page\s*\d+</b><br>)

The other:

(<A\s*name=\d+></a>)

But this might actually be useful to keep, to allow navigation in the book. It is a bookmark that you can navigate to from a table of contents.

Regular expressions are written using a rudimentary language, with synonyms and many different ways to express the same thing. Some ways may be better/smarter/prettier/more robust than others.

Last edited by Adoby; 08-29-2010 at 07:58 AM.
Adoby is online now   Reply With Quote