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

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 01-29-2014, 08:51 AM   #1
Alt68er
Member
Alt68er began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Dec 2013
Device: Pocketbook touch lux (623)
search/replace multiline regex

Hi,

I have a real lot of books all having the following head:

Code:
<head>
  <meta content="2009-03-15T01:30:38" name="date" />
  <meta content="OpenOffice.org/3.0$Linux OpenOffice.org_project/300m15$Build-9379" name="generator" />

  <title>Unknown</title>
  <link href="../Styles/stylesheet.css" rel="stylesheet" type="text/css" />
  
<style type="text/css">
@page { margin-bottom: 5.000000pt; margin-top: 5.000000pt; }
</style>
</head>

<body class="calibre">
which I want replace within each book with "my own" header but retaining the part

Code:
  <title>Unknown</title>
  <link href="../Styles/stylesheet.css" rel="stylesheet" type="text/css" />
In the meantime I already have a little experience with regexes but here I am overextended.

Can anyone help me with a regex finding the first code?

With the replace function I'll not have any problems.

1000 thanks in advnce for your kind help!

Peter
Alt68er is offline   Reply With Quote
Old 01-29-2014, 10:35 AM   #2
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 2,911
Karma: 1163098
Join Date: Sep 2010
Device: Kobo aura HD, Kobo Arc, Kindle Fire HDX 8.9 , Kindle for PC
is it as simple as finding everyting between
<meta
and
<title
?
find <meta(.*)<title

or between head and title
find <head>(.*)<title
cybmole is online now   Reply With Quote
Old 01-29-2014, 12:01 PM   #3
theducks
Grand Sorcerer
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: 14,903
Karma: 5880479
Join Date: Aug 2009
Location: (The original) Silicon Valley, USA
Device: Galaxy Tab 2, Astak Pocket Pro, K4NT
There is a gotcha lurking .
I don't believe that the the contents of <head>has to be in any specific order.

Why worry: just capture the Title: (<title>.*</title>) and forget the Style (if the same stylesheet is used)

Replace the <head> with your boilerplate that has a \1 where the <title> goes. THEN use Link stylesheets to reestablish control
theducks is offline   Reply With Quote
Old 01-29-2014, 02:09 PM   #4
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 9,311
Karma: 42858084
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Find (with "dotAll" box checked):
Code:
<head>.*?</head>
Replace with:
Code:
<head><title>Unknown</title></head>
Then highlight multiple files and use the right-click->"Link Stylesheets" to relink your stylesheet like theducks mentioned.

Or replace with:
Code:
<head><title>Unknown</title><link href="../Styles/stylesheet.css" rel="stylesheet" type="text/css" /></head>
if you so like.
DiapDealer is online now   Reply With Quote
Old 02-01-2014, 09:40 AM   #5
Alt68er
Member
Alt68er began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Dec 2013
Device: Pocketbook touch lux (623)
Hi and thanks a lot for your suggestions.

With your help I found the following find-regex

Code:
(?s)<head>.*(  <title.*css\"\ {0,1}/>).*<body class="calibre">
and this replace-regex:

Code:
(?s)<head>.*(  <title.*css\"\ {0,1}/>).*<body class="calibre">
which are working absolutely fine.

Thanks again and a nice weekend,
Peter
Alt68er is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex search and replace dwlamb Sigil 6 04-12-2013 02:34 PM
Regex help: Edit Meta Search & Replace: Pad with zero _noel_ Calibre 4 11-26-2012 04:31 PM
regex search/replace Sharlene Sigil 10 01-28-2012 04:14 AM
Search & Replace/Regex help!! millertime13 Conversion 4 07-22-2011 02:40 AM
need regex help search and replace schuster Calibre 4 01-10-2011 09:00 AM


All times are GMT -4. The time now is 04:34 AM.


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