Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 12-12-2018, 09:03 PM   #1
RbnJrg
Guru
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: 908
Karma: 3311651
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, 07:19 AM   #2
Vroni
Member
Vroni began at the beginning.
 
Posts: 10
Karma: 10
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, 11:09 AM   #3
KevinH
Wizard
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: 3,141
Karma: 1931746
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, 11:39 AM   #4
RbnJrg
Guru
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: 908
Karma: 3311651
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
[QUOTE=Vroni;3786132]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
[quote]

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.
RbnJrg is offline   Reply With Quote
Old 12-13-2018, 11:40 AM   #5
RbnJrg
Guru
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: 908
Karma: 3311651
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, 12:27 PM   #6
jackie_w
Wizard
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: 4,708
Karma: 11302999
Join Date: Sep 2009
Location: UK
Device: PRS-350, Kobo: Aura6", H2O, GloHD, KA1, ClaraHD, Forma
@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 12:39 PM.
jackie_w is offline   Reply With Quote
Old 12-13-2018, 12:32 PM   #7
Doitsu
Wizard
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: 4,382
Karma: 14368669
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, 03:19 PM   #8
RbnJrg
Guru
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: 908
Karma: 3311651
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, 03:21 PM   #9
RbnJrg
Guru
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: 908
Karma: 3311651
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, 06: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,233
Karma: 500084
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, 03:54 AM   #11
Vroni
Member
Vroni began at the beginning.
 
Posts: 10
Karma: 10
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, 07:32 AM   #12
RbnJrg
Guru
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: 908
Karma: 3311651
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, 07:58 AM   #13
Vroni
Member
Vroni began at the beginning.
 
Posts: 10
Karma: 10
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

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 04:08 PM.


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