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 07-27-2020, 08:30 PM   #1
Ted Friesen
Nameless Being
 
Replace truncating found text

Using this search: <p><b>([A-Z]+\s[A-Z]+)+</b></p>

the following string was found and the entire string was highlighted
<p><b>MEDICATIONS THAT CAUSE WEIGHT GAIN</b></p>

but applying this replace: <h4>\1</h4>

I got the following truncated result <h4>T GAIN</h4>

What I was hoping to do was to find all occurrences of
<p><b>ONLY WORDS IN CAPS</b></p>, regardless of the number of words and replace it with <h4>ONLY WORDS IN CAPS</h4>. Looking to capture strings of two or more words.
  Reply With Quote
Old 07-27-2020, 08:45 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: 37,758
Karma: 150186866
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by Ted Friesen View Post
Using this search: <p><b>([A-Z]+\s[A-Z]+)+</b></p>

the following string was found and the entire string was highlighted
<p><b>MEDICATIONS THAT CAUSE WEIGHT GAIN</b></p>

but applying this replace: <h4>\1</h4>

I got the following truncated result <h4>T GAIN</h4>

What I was hoping to do was to find all occurrences of
<p><b>ONLY WORDS IN CAPS</b></p>, regardless of the number of words and replace it with <h4>ONLY WORDS IN CAPS</h4>. Looking to capture strings of two or more words.
Perhaps if you edited your search string to allow white space as an allowed character?
Code:
<p><b>([A-Z\s]+)+</b></p>
DNSB is offline   Reply With Quote
Advert
Old 07-28-2020, 02:04 AM   #3
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,906
Karma: 47303822
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
I'm pretty sure that extra plus sign is culprit. So:

Code:
<p><b>([A-Z\s]+)</b></p>
That's assuming there is no other punctuation. Or numbers or anything. I frequently use:

Code:
<p><b>(.+?)</b></p>
That just grabs everything between those tags but isn't greedy, so it won't be to dangerous.

Or maybe:

Code:
<p><b>(.+\w)</b></p>
That would help if there are paragraphs that are in bold as well as titles. It assumes the titles don't have punctuation at the end.

Disclaimer: These are completely untested.
davidfor is offline   Reply With Quote
Old 07-30-2020, 02:19 PM   #4
Ted Friesen
Nameless Being
 
Thanks guys for the ideas.

I'll try them out. My reason for not using <p><b>(.+?)</b></p> or <p><b>(.+\w)</b></p> was that I needed to catch only capitalized words.
  Reply With Quote
Old 07-30-2020, 04:31 PM   #5
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
This seems to work for me in Sigil:
Code:
<p><b>([[:upper:]+[:blank:]]+)</b></p>
Whereas in its ASCII form it does not:
Code:
<p><b>([[A-Z]+[ \t]]+)</b></p>
Score one for verbose POSIX.

Last edited by hobnail; 07-30-2020 at 04:34 PM.
hobnail is offline   Reply With Quote
Advert
Old 07-30-2020, 05:22 PM   #6
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: 37,758
Karma: 150186866
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
I'm beginning to get the feeling that this thread has devolved into how many different regexes will give the same result.
DNSB 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
Search and replace returns entire field when no match is found wladdy Calibre 2 02-16-2014 01:51 AM
Search-and-Replace with a found number Lamen Conversion 6 11-02-2012 08:51 PM
HTML tables truncating after converting to epub SEI Publications Conversion 7 05-06-2011 06:53 PM
I finally found a device to replace my Palm PDA Nate the great Alternative Devices 50 12-10-2008 04:32 PM
I found way to vastly improve displaying of text! Malder1 iRex 43 01-05-2007 05:32 PM


All times are GMT -4. The time now is 02:29 PM.


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