![]() |
#1 |
Member
![]() Posts: 20
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"> Code:
<title>Unknown</title> <link href="../Styles/stylesheet.css" rel="stylesheet" type="text/css" /> 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 |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
is it as simple as finding everyting between
<meta and <title ? find <meta(.*)<title or between head and title find <head>(.*)<title |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,909
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
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 ![]() |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,358
Karma: 203720150
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Find (with "dotAll" box checked):
Code:
<head>.*?</head> Code:
<head><title>Unknown</title></head> Or replace with: Code:
<head><title>Unknown</title><link href="../Styles/stylesheet.css" rel="stylesheet" type="text/css" /></head> |
![]() |
![]() |
![]() |
#5 |
Member
![]() Posts: 20
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"> Code:
(?s)<head>.*( <title.*css\"\ {0,1}/>).*<body class="calibre"> Thanks again and a nice weekend, Peter |
![]() |
![]() |
Advert | |
|
![]() |
|
![]() |
||||
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 |