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 09-17-2023, 11:19 AM   #1
MerlinMama
Evangelist
MerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beauty
 
MerlinMama's Avatar
 
Posts: 482
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Sage
Regex - How to remove a word, capitalize next

Is there a way to replace "But they wanted..." with "They wanted..." in one search and replace operation, or do I need to continue with my current two-step process? (Remove 'But' in first, capitalize 'they' in the second)
MerlinMama is offline   Reply With Quote
Old 09-17-2023, 01:10 PM   #2
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 35,489
Karma: 145557716
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
You could search for 'But ([a-z])' and replace with '\u\1' which will replace any But followed by a lower case letter with the upper case letter.
DNSB is offline   Reply With Quote
Advert
Old 09-17-2023, 01:22 PM   #3
MerlinMama
Evangelist
MerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beauty
 
MerlinMama's Avatar
 
Posts: 482
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Sage
I get the following error when I try to run it

Code:
calibre, version 6.26.0
ERROR: Unhandled exception: <b>error</b>:incomplete escape \u at position 3

calibre 6.26  embedded-python: True
Windows-10-10.0.22621-SP0 Windows ('64bit', 'WindowsPE')
('Windows', '10', '10.0.22621')
Python 3.10.1
Windows: ('10', '10.0.22621', 'SP0', 'Multiprocessor Free')
Interface language: None
Successfully initialized third party plugins: Count Pages (1, 13, 2) && Diaps Editing Toolbag (0, 4, 0) && FanFicFare (4, 27, 0) && Favourites Menu (1, 3, 0) && Find Duplicates (1, 10, 8) && Generate Cover (2, 3, 3) && Job Spy (1, 0, 239) && Kobo Utilities (2, 16, 10) && Save To Format (0, 0, 6) && View Manager (1, 10, 2)
Traceback (most recent call last):
  File "calibre\gui2\tweak_book\boss.py", line 1129, in search
  File "calibre\gui2\tweak_book\search.py", line 1562, in run_search
  File "calibre\gui2\tweak_book\search.py", line 1469, in do_replace
  File "calibre\gui2\tweak_book\editor\widget.py", line 328, in replace
  File "calibre\gui2\tweak_book\editor\text.py", line 599, in replace
  File "regex\regex.py", line 700, in _compile_replacement_helper
  File "regex\_regex_core.py", line 1690, in _compile_replacement
  File "regex\_regex_core.py", line 1757, in parse_repl_hex_escape
regex._regex_core.error: incomplete escape \u at position 3
MerlinMama is offline   Reply With Quote
Old 09-17-2023, 02:13 PM   #4
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 35,489
Karma: 145557716
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Sorry about that. I'm more used to the dialect of Regex used by Sigil which does accept \u to convert to one character to upper case.

According to a post by Kovid Goyal, calibre does not support \u and you will need to use function mode: https://manual.calibre-ebook.com/function_mode.html which is considerably more complex.

Yet another reason that I use both calibre's ebook-editor and Sigil. They both offer capability that the other does not.

Last edited by DNSB; 09-17-2023 at 02:17 PM.
DNSB is offline   Reply With Quote
Old 09-23-2023, 07:27 PM   #5
lomkiri
Zealot
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
Easy enough:
Search : But ([a-z])
regex-function :
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    return match[1].upper()
lomkiri is offline   Reply With Quote
Advert
Old 09-23-2023, 09:47 PM   #6
MerlinMama
Evangelist
MerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beauty
 
MerlinMama's Avatar
 
Posts: 482
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Sage
Thank you, that worked! I really appreciate it.
MerlinMama is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Capitalize first letter of each word mortenanakin Calibre 1 08-06-2021 01:41 PM
Help! I broke my Capitalize Regex function. staceytoob Editor 2 07-28-2021 09:48 PM
How to remove blank spaces in a word with RegEx? RbnJrg Sigil 12 12-19-2018 06:58 AM
regex capitalize first letter larysa Editor 8 10-23-2017 12:04 PM
[Old Thread] Capitalize first word in sentence with search and replace? ianc Conversion 6 10-21-2013 04:47 PM


All times are GMT -4. The time now is 01:33 AM.


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