Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 01-10-2011, 08:10 AM   #1
schuster
Zealot
schuster doesn't litterschuster doesn't litter
 
Posts: 119
Karma: 100
Join Date: Jan 2011
Location: Germany / NRW /Köln
Device: prs-650 / prs-350 /kindle 3
need regex help search and replace

hy,
i want to ask if someone can help me with a "maybe simple" regex.

sample:
Gwin hatte ihn noch nie<br>
gesehen.<br>
»Ich weiß nicht...«<br>

before every <br> is a linebreak, so it shows not good in epub version.

how can i eleminate the linebreake and <br> if the line counts overall <20 including whitespace?

my first test to get it:

<br>\n(?=.{0,20}<br>)

now it get the lb and <br> bevor the short text and put it together.
how can i insert a whitespace between.

the sample above shows like:

Gwin hatte ihn noch niegesehen.<br> instead of:

Gwin hatte ihn noch nie gesehen.<br>



thanks for your help to a newbie

olaf
schuster is offline   Reply With Quote
Old 01-10-2011, 08:17 AM   #2
itimpi
Wizard
itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.
 
Posts: 4,552
Karma: 950151
Join Date: Nov 2008
Device: Sony PRS-950, iphone/ipad (Marvin/iBooks/QuickReader)
You can use '\d*' to match a number of any length.

Also useful along the same lines is '\s*' to match whitespace of any length (spaces, newlines, tabs).
itimpi is offline   Reply With Quote
Advert
Old 01-10-2011, 08:32 AM   #3
schuster
Zealot
schuster doesn't litterschuster doesn't litter
 
Posts: 119
Karma: 100
Join Date: Jan 2011
Location: Germany / NRW /Köln
Device: prs-650 / prs-350 /kindle 3
hy itimpi,
this is clear.
but i want to replace the complete matching string
to a new one "with" whitespace. i'm not a pro so i can't find the right syntax to do a replace with ws.
the matching number is in between 0-20 so i can't get a fix number for the position on which i had to make a replace.
schuster is offline   Reply With Quote
Old 01-10-2011, 08:39 AM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,713
Karma: 6690879
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
You must be using something like \1 as the replace string. Why can't you put a space in the beginning?

What happens if you use the search string
<br>(?=\n.{0,20}<br>)
and leave the newline there? The reader should ignore newlines, converting them to spaces, which is what you seem to want.
chaley is offline   Reply With Quote
Old 01-10-2011, 09:00 AM   #5
schuster
Zealot
schuster doesn't litterschuster doesn't litter
 
Posts: 119
Karma: 100
Join Date: Jan 2011
Location: Germany / NRW /Köln
Device: prs-650 / prs-350 /kindle 3
hy chaley,

tested, wondered, worx

now it looks great. many things are simple. but let me say, i have seen so many trees that i can't see the forest. great work.

i hope any of the users here can do anything with this regex i had made to get most of pagenumbering, hyphen, word separation and so on, out of my text.

(<br>\n?-?\s{,40}[0-9]{1,4}\s{,40}-?\s{,40}(<?b?r?>?|<?b?>?)\n?<hr>\n?\s?(?=<A name=))|(\s?-\s?<?/?i?>?<br>\s?\n?\s?(<i>)?(?=[a-z]))|(<br>\s?\s?\S?\s?\s?\S?\s?\s?\S?\s?\s?[0-9]{1,4}\s?\s?\S?\s?\s?\S?
\s?\s?\S?\s?\s?<br>\s?\n?<hr>\s?\n?(?=<A name=))|(<br>\s?\n?<hr>\s?\n?<A name=[0-9]{1,4}></a>[0-9]{1,4}\s?\n?<br>)|(<b>\s{0,25}-\s{0,25}[0-9]{1,4}\s{0,5}([0-9]{0,1}?)\s{0,5}([0-9]{0,1}?)\s{0,25}-\s{0,25}</b><br>\n<hr>\n(?=<A name=[0-9]{1,4}>))|(</a><b> </b><br>)|\n(?=.{0,25}<br>)|<br>(?=\n.{0,20}<br>)


i hope that will be corrected or extended by the prof's in here.

for this time i say thanks

regards olaf
schuster is offline   Reply With Quote
Advert
Reply

Tags
calibre, regex, syntax

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
REGEX find and replace help please potestus Sigil 13 09-18-2010 04:14 PM
Search and replace in 0.2.0 paulpeer Sigil 7 03-13-2010 11:59 AM
Regex search author field to locate books? Starson17 Calibre 2 12-21-2009 10:40 AM
regex search for roman numerals Blurr Calibre 2 12-16-2009 05:55 PM
Why no search and replace? charleski Sigil 10 11-24-2009 04:13 PM


All times are GMT -4. The time now is 09:15 AM.


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