Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 12-12-2018, 08:03 PM   #1
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,542
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Question How to remove blank spaces in a word with RegEx?

Hi friends:

I have something like:

Code:
<h1 title="My Title">C H A P T E R  1</h1>
and I want:

Code:
<h1 title="My Title">CHAPTER 1</h1>
How can I do that with RegEx?

TIA

Rubén
RbnJrg is offline   Reply With Quote
Old 12-13-2018, 06:19 AM   #2
Vroni
Banned
Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'
 
Posts: 168
Karma: 10010
Join Date: Oct 2018
Device: Tolino/PRS 650/Tablet
Depends. It can be impossible or very easy. If its always the word CHAPTER, tats easy, and i guess you woudn't have asked

If all letters are capital you can just search for ([A-Z])_ and reaplce it with \1. The probality that a capital letter is followed by a blank is low, but not 0. So yo have to go through the text one at a time to make a decision.

In any other case i would assume its not possible as Regex in sigil cant be limited to work only inside a specific element (AFAIR Calibre can do that) So you are catching too many wrong positives if your heading is mixed-case.
Vroni is offline   Reply With Quote
Old 12-13-2018, 10:09 AM   #3
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: 7,644
Karma: 5433388
Join Date: Nov 2009
Device: many
Simply add that element to the reflex pattern if you only want to search inside a specific tag element
KevinH is offline   Reply With Quote
Old 12-13-2018, 10:39 AM   #4
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,542
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Vroni View Post
Depends. It can be impossible or very easy. If it's always the word CHAPTER, that's easy, and i guess you woudn't have asked
Yes, not always the word is CHAPTER.

Quote:
If all letters are capital you can just search for ([A-Z])_ and reaplce it with \1. The probality that a capital letter is followed by a blank is low, but not 0. So yo have to go through the text one at a time to make a decision.
Not always the letters are in uppercase. Sometimes only the first letter is capitalized.

Quote:
In any other case i would assume it's not possible as Regex in sigil can't be limited to work only inside a specific element (AFAIR Calibre can do that). So you are catching too many wrong positives if your heading is mixed-case.
I didn't know that Calibre could work with RegEx inside a specific element. I'll do a research to see what can I get there. Thanks for the info.

Last edited by RbnJrg; 06-06-2021 at 03:22 PM.
RbnJrg is offline   Reply With Quote
Old 12-13-2018, 10:40 AM   #5
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,542
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by KevinH View Post
Simply add that element to the reflex pattern if you only want to search inside a specific tag element
And how do I do that?
RbnJrg is offline   Reply With Quote
Old 12-13-2018, 11:27 AM   #6
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
@RbnJrg,

This is stretching my limited regex lookahead knowledge The closest I could get (tested in calibre) was something like:
Code:
Find:\b([a-z])\s+(?=(\w\s+\w))
Replace:\1
with case-sensitivity disabled.

I think you'd need to replace them one-by-one not 'Replace All'.

Last edited by jackie_w; 12-13-2018 at 11:39 AM.
jackie_w is offline   Reply With Quote
Old 12-13-2018, 11:32 AM   #7
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by RbnJrg View Post
I didn't know that Calibre could work with RegEx inside a specific element. I'll do a research to see what can I get there. Thanks for the info.
I rarely use Calibe Editor, but the following should work for you.
  • Paste <h1([^>]*)>([^<]+)</h1> in the Find box.
  • Select Regex-function from the Mode drop-down box.
  • Click Create/Edit, paste the following code in the Code box:


    Code:
    def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
        return '<h1' + match.group(1) + '>'  + match.group(2).replace('  ', '§').replace(' ', '').replace('§', ' ') + '</h1>'
    enter a function name, e.g. Ruben, and click OK.
Doitsu is offline   Reply With Quote
Old 12-13-2018, 02:19 PM   #8
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,542
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by jackie_w View Post
@RbnJrg,

This is stretching my limited regex lookahead knowledge The closest I could get (tested in calibre) was something like:
Code:
Find:\b([a-z])\s+(?=(\w\s+\w))
Replace:\1
with case-sensitivity disabled.

I think you'd need to replace them one-by-one not 'Replace All'.
Thank you very much for your response Jackie. It almost worked When I have, for example:

Code:
C H A P T E R  V I I I
after applying your code, I have:

Code:
CHAPTERVII I
Where my strings are all in uppercase, I can use your code with \b([A-Z])\s+(?=(\w\s+\w)) and case-sensivity enabled and I can do the work at once. So, if it were possible to solve the issue, your RegEx is very usefull.
RbnJrg is offline   Reply With Quote
Old 12-13-2018, 02:21 PM   #9
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,542
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Doitsu View Post
I rarely use Calibe Editor, but the following should work for you.
  • Paste <h1([^>]*)>([^<]+)</h1> in the Find box.
  • Select Regex-function from the Mode drop-down box.
  • Click Create/Edit, paste the following code in the Code box:


    Code:
    def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
        return '<h1' + match.group(1) + '>'  + match.group(2).replace('  ', '§').replace(' ', '').replace('§', ' ') + '</h1>'
    enter a function name, e.g. Ruben, and click OK.
Thank you very much Doitsu; your code worked like a charm!
RbnJrg is offline   Reply With Quote
Old 12-13-2018, 05:09 PM   #10
Notjohn
mostly an observer
Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.
 
Posts: 1,515
Karma: 987654
Join Date: Dec 2012
Device: Kindle
Quote:
Originally Posted by RbnJrg View Post
Thank you very much Doitsu; your code worked like a charm!
Sometimes I log onto the Sigil just to marvel at the things people come up with!
Notjohn is offline   Reply With Quote
Old 12-17-2018, 02:54 AM   #11
Vroni
Banned
Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'
 
Posts: 168
Karma: 10010
Join Date: Oct 2018
Device: Tolino/PRS 650/Tablet
By the was, are there any other spaces besides blank spaces?
Vroni is offline   Reply With Quote
Old 12-18-2018, 06:32 AM   #12
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,542
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Vroni View Post
By the way, are there any other spaces besides blank spaces?
No, only blank spaces.
RbnJrg is offline   Reply With Quote
Old 12-19-2018, 06:58 AM   #13
Vroni
Banned
Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'
 
Posts: 168
Karma: 10010
Join Date: Oct 2018
Device: Tolino/PRS 650/Tablet
I would like to have seven red lines, some painted with red ink, some with green ink and some with transparent ink.

"The experts, Youtube"
Vroni is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing spaces for regex roger64 Sigil 10 12-05-2017 09:26 PM
regex - issue with spaces? cybmole Editor 43 12-31-2013 12:49 PM
How to remove blank spaces? Mamaijee Conversion 2 04-09-2013 11:20 AM
Blank spaces after header is removed Mamaijee Conversion 2 05-26-2011 01:17 PM
Missing blank spaces in ToC richough3 ePub 3 09-10-2009 05:33 PM


All times are GMT -4. The time now is 03:57 AM.


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