01-10-2011, 08:10 AM | #1 |
Zealot
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 |
01-10-2011, 08:17 AM | #2 |
Wizard
Posts: 4,553
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). |
Advert | |
|
01-10-2011, 08:32 AM | #3 |
Zealot
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. |
01-10-2011, 08:39 AM | #4 |
Grand Sorcerer
Posts: 11,942
Karma: 7219261
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. |
01-10-2011, 09:00 AM | #5 |
Zealot
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 |
Advert | |
|
Tags |
calibre, regex, syntax |
|
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 |