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

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 10-14-2019, 08:58 AM   #1
PenguinCEO
Member
PenguinCEO began at the beginning.
 
Posts: 23
Karma: 10
Join Date: Sep 2018
Device: a lot
Help for a regex

I have the following regex

Code:
<h(\d).*?>.*?</h\1>
and it works.

Now I want to replace for every occurrence of the found string the same string but prepended with a string of choice, say "<!-- title -->\n"

So, if the string found by the above regex was

Code:
<h1 class="veryhigh">lorem ipsum</h1>
it should been replaced by the string

Code:
<!-- title -->\n<h1 class="veryhigh">lorem ipsum</h1>
In other words, is there in the calibre regexes something like the expression "$&" in Perl?
PenguinCEO is offline   Reply With Quote
Old 10-14-2019, 09:36 AM   #2
Brett Merkey
Not Quite Dead
Brett Merkey shares his or her toysBrett Merkey shares his or her toysBrett Merkey shares his or her toysBrett Merkey shares his or her toysBrett Merkey shares his or her toysBrett Merkey shares his or her toysBrett Merkey shares his or her toysBrett Merkey shares his or her toysBrett Merkey shares his or her toysBrett Merkey shares his or her toysBrett Merkey shares his or her toys
 
Posts: 104
Karma: 5750
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
No, there is no special regex in Calibre that does that. but what you want seems easy enough:

Quote:
Find: (<h(\d).*?>.*?</h\2>)
Replace: <!-- title -->\n\1
It tests fine.
Brett Merkey is offline   Reply With Quote
Advert
Old 10-14-2019, 10:39 AM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 35,476
Karma: 12737927
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
There is something a lot better: https://manual.calibre-ebook.com/function_mode.html
kovidgoyal 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 help please bremler Workshop 4 04-15-2017 01:22 AM
Need regex help, please magmanpi Sigil 13 08-29-2014 05:34 AM
Need help with a regex mobiuser Workshop 15 01-19-2014 06:57 PM
Need help for a regex wobohohoho Sigil 4 01-02-2013 05:42 AM
Help with a regex A.T.E. Calibre 1 04-05-2010 08:50 AM


All times are GMT -4. The time now is 02:10 AM.


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