Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 08-29-2024, 06:32 PM   #1
bookimp13
Junior Member
bookimp13 began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Aug 2022
Device: Galaxy Tab A 8.0 (2019)
Find/Replace wildcard?

I'm trying to replace this

<head><title>DSF Chapter 3 Chapter 3</title>

With this

<head><title>Chapter 3</title>

And while I could certainly get rid of 'DSF Chapter ' I'm not sure how to get rid of that 3.

I'm definitely a newbie to Sigil so please use 'Sigil for dummies' phrases
bookimp13 is offline   Reply With Quote
Old 08-29-2024, 08:04 PM   #2
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,156
Karma: 5450818
Join Date: Nov 2009
Device: many
What you are looking for is called Regular Expression Find and Replace (aka regex).
This mode enable placeholders for specific character classes. Digits are represented by \d,
and a following + sign means 1 or more.

So set Sigil's Find and Replace Mode to Regex.

Try using something like the following in the Find Field:

DSF Chapter \d+

Before making any big Find Replace changes, I would make a Checkpoint just in case a big find and replace does not work the way you expect.

Sigil also has a DryRun Find and Replace command that will show you all the Find and Replaces done in context but not actually perform them, so you can test your regex expressions first.

Last edited by KevinH; 08-29-2024 at 08:10 PM.
KevinH is online now   Reply With Quote
Advert
Old 08-29-2024, 08:16 PM   #3
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,220
Karma: 19000635
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
Try:

Find: <title>.*?Chapter\s*(\d*?)\s*.*?</title>
Replace: <title>Chapter \1</title>

<title> & </title> are just the bounding tags
.*? is any number (or none) of any characters
\s* is any number (or none) spaces
(\d+?) is 1 or more numerical digits and it remembers what it finds


The Replace simply inserts the remembered digits into the phrase using the \1.


There are some good regex tutorials that will really help when editing code. It doesn't take long to get the basics....it does take forever to become a master... I'm definitely not there yet!

Make sure you focus on the PCRE flavor of Regex...that is what Sigil uses.


Cheers,
Turtle91 is offline   Reply With Quote
Old 08-29-2024, 09:00 PM   #4
bookimp13
Junior Member
bookimp13 began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Aug 2022
Device: Galaxy Tab A 8.0 (2019)
Quote:
Originally Posted by KevinH View Post
What you are looking for is called Regular Expression Find and Replace (aka regex).
This mode enable placeholders for specific character classes. Digits are represented by \d,
and a following + sign means 1 or more.

So set Sigil's Find and Replace Mode to Regex.

Try using something like the following in the Find Field:

DSF Chapter \d+

Before making any big Find Replace changes, I would make a Checkpoint just in case a big find and replace does not work the way you expect.

Sigil also has a DryRun Find and Replace command that will show you all the Find and Replaces done in context but not actually perform them, so you can test your regex expressions first.
This worked great thank you!
bookimp13 is offline   Reply With Quote
Old 08-29-2024, 09:01 PM   #5
bookimp13
Junior Member
bookimp13 began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Aug 2022
Device: Galaxy Tab A 8.0 (2019)
Quote:
Originally Posted by Turtle91 View Post
Try:

Find: <title>.*?Chapter\s*(\d*?)\s*.*?</title>
Replace: <title>Chapter \1</title>

<title> & </title> are just the bounding tags
.*? is any number (or none) of any characters
\s* is any number (or none) spaces
(\d+?) is 1 or more numerical digits and it remembers what it finds


The Replace simply inserts the remembered digits into the phrase using the \1.


There are some good regex tutorials that will really help when editing code. It doesn't take long to get the basics....it does take forever to become a master... I'm definitely not there yet!

Make sure you focus on the PCRE flavor of Regex...that is what Sigil uses.


Cheers,
Bookmarked thanks!
bookimp13 is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/Replace ? Otter Calibre 2 10-08-2012 09:48 PM
Find Replace unrulyguides Sigil 5 02-17-2012 09:38 PM
Find/Replace Won't Find Rand Brittain Sigil 7 09-24-2011 05:35 AM
Find and replace string with wildcard jhempel24 Sigil 15 11-12-2010 02:50 PM
Using Find/Replace with BD Otter Sony Reader 7 02-28-2009 02:49 PM


All times are GMT -4. The time now is 12:39 PM.


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