Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 08-04-2019, 07:26 PM   #1
The_Goblin
Junior Member
The_Goblin began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Aug 2019
Device: none
Replacing //.+// with <i>.+</i>

So in an ebook I'm converting from html, I need to replace all the text between "//" with the same text, but italics tags in place of the slashes.

I've spent a few hours mashing my face into learning regex and I can't figure out what seems like a simple task. I even tried in Word, and couldn't manage it there either. Can anyone help?

For Example:

// How is this possible? // I wondered to myself. // I simply can't see how to do it. //
Needs to become:

<i>How is this possible?</i> I wondered to myself. <i>I simply can't see how to do it.</i>

Or

It's all over my head. // This is why I got a C in compsci. // I hope someone can help me.
Needs to become:
It's all over my head. <i>This is why I got a C in compsci.</i> I hope someone can help me.
The_Goblin is offline   Reply With Quote
Old 08-04-2019, 08:02 PM   #2
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Try:

Code:
\/\/\s(.*?)\s\/\/
The slashes need to be escaped, hence "\/". Then a space, "\s" and "(.*?)" is capture any text but not the space before the closing doubleslashes.

With the replacement:

Code:
<i>\1</i>
Note, for the search, I would probably use:

Code:
\/\/\s*(.*?)\s*\/\/
That covers any amount of whitespace around the text. With either, you need to be careful in case there missing doubleslashes.

Last edited by davidfor; 08-04-2019 at 10:04 PM. Reason: Fixing second example.
davidfor is offline   Reply With Quote
Advert
Old 08-04-2019, 09:04 PM   #3
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
Quote:
//\s*(.*?)\s*\/\/
To be nit picky, I assume you meant to escape the leading //


Code:
\/\/\s*(.*?)\s*\/\/
phossler is offline   Reply With Quote
Old 08-04-2019, 09:39 PM   #4
The_Goblin
Junior Member
The_Goblin began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Aug 2019
Device: none
Ty :D



Code:
\/\/\s*(.*?)\s*\/\/
worked perfectly as the "Find" and
Code:
 <i>\1</i>
worked perfectly as the "Replace".

Thank you both so much!
The_Goblin is offline   Reply With Quote
Old 08-04-2019, 10:19 PM   #5
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by phossler View Post
To be nit picky, I assume you meant to escape the leading //


Code:
\/\/\s*(.*?)\s*\/\/
Yep. Testing and cut-and-paste error. Fixed in the post.
davidfor is offline   Reply With Quote
Advert
Old 08-05-2019, 12:09 AM   #6
The_Goblin
Junior Member
The_Goblin began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Aug 2019
Device: none
A Little Tweak

Looks like I spoke too soon, none of the expressions caught all of the //. However, I did figure a solution, so if you need something similar and the prior answers don't work quite right, try this:

Code:
//\s*(.*?)\s*\/\D
(with "dot all" checked) It did not make a difference if the first two // were escaped.

It wasn't flawless, it would catch:
Code:
//Me? You can't be me. <i class="calibre4">I'm</i> me.//
Here's an example of what the other solutions selected, in red:

Code:
// Could
    it be? // he asked himself, // could it possibly be after so,
    so very long? //
Code:
(all text until prior //) He projected as strongly as he could. // Center,  C'mon. You can do this. You CAN. //
The_Goblin is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PRS-T1 Replacing screen dave45 Sony Reader 4 09-06-2013 11:07 AM
Replacing the battery msoulier Kobo Reader 2 09-28-2012 09:24 PM
Replacing code without replacing text? ElMiko Sigil 6 11-30-2011 08:14 PM
Replacing my Hanlin V3 maddz Which one should I buy? 0 11-25-2010 04:14 AM
Replacing ¬ PieOPah Workshop 5 12-17-2008 04:25 PM


All times are GMT -4. The time now is 08:00 AM.


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