Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 02-17-2014, 11:47 AM   #1
Alt68er
Member
Alt68er began at the beginning.
 
Posts: 20
Karma: 10
Join Date: Dec 2013
Device: Pocketbook touch lux (623)
Regex search/replace with conditions

Hi,
since a short time I'm re-editing a series of weeklys and I'm already a little bit familiar with regexes.
But up to the moment I did not find a regex which can do the following:

I want to replace in a lot of the weeklys 3 dots by the … (…). The difficulty is, that in some cases the 3 dots are directly preceded by a letter, sometimes by a blank/space.
I want to find both cases with one search and replace them with "blank…" if directly preceded by any kind of letter etc. or only with the … if they are preceded by a blank already.

Can anyone of you experts give me a hint how to get it working?

1000 thanks and advance,
Peter

Last edited by Jellby; 02-17-2014 at 02:59 PM. Reason: add markup to avoid smileys
Alt68er is offline   Reply With Quote
Old 02-17-2014, 12:28 PM   #2
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,727
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
There's probably a more elegant solution, but I'd simply search for an optional space followed by three dots and replace it with a space and …

Find:\s*\.\.\.
Replace: …
Doitsu is offline   Reply With Quote
Advert
Old 02-17-2014, 02:05 PM   #3
Marcs1102
Member
Marcs1102 has memorized the entire works of Homer, Shakespeare, and Jane AustenMarcs1102 has memorized the entire works of Homer, Shakespeare, and Jane AustenMarcs1102 has memorized the entire works of Homer, Shakespeare, and Jane AustenMarcs1102 has memorized the entire works of Homer, Shakespeare, and Jane AustenMarcs1102 has memorized the entire works of Homer, Shakespeare, and Jane AustenMarcs1102 has memorized the entire works of Homer, Shakespeare, and Jane AustenMarcs1102 has memorized the entire works of Homer, Shakespeare, and Jane AustenMarcs1102 has memorized the entire works of Homer, Shakespeare, and Jane AustenMarcs1102 has memorized the entire works of Homer, Shakespeare, and Jane AustenMarcs1102 has memorized the entire works of Homer, Shakespeare, and Jane AustenMarcs1102 has memorized the entire works of Homer, Shakespeare, and Jane Austen
 
Posts: 23
Karma: 23332
Join Date: Jan 2013
Device: none
you may want to consider a double rename (ie standard rename first to rename all "..." to " ..." and then your regex renamer to look for "..."
Marcs1102 is offline   Reply With Quote
Old 02-17-2014, 03:04 PM   #4
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,548
Karma: 19500001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
The idea is not to use conditions (replace with this if it has a space, and with that otherwise), but to include all cases in the same condition (replace "..." preceded by zero or more spaces, all of that, with " …").

If you want to be more specific (replace only if there is a letter before the zero-or-more spaces, replace at most one space, etc.) it can be done too.
Jellby is offline   Reply With Quote
Old 02-18-2014, 01:45 AM   #5
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
i think , nitpicking here, gramatically, if there is no leading space, then you should not be adding one.

I once spent ages googling the grammar rules for this stuff & Have forgotten most of it but I do remember there are times when you have a leading space, times when you don't

Also, on an e-reader, I hate seeing the … appear on a new line all by itself, so I would add an   not a regular space.
cybmole is offline   Reply With Quote
Advert
Old 02-18-2014, 02:44 AM   #6
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,727
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by Marcs1102 View Post
you may want to consider a double rename (ie standard rename first to rename all "..." to " ..." and then your regex renamer to look for "..."
If the OP did that, he might end up with an ellipsis preceded by two spaces. Besides, since my regular expression will find both "..." and " ..." there's no point in using two search and replace operations instead of one.

Quote:
Originally Posted by cybmole View Post
Also, on an e-reader, I hate seeing the … appear on a new line all by itself, so I would add an   not a regular space.
That's what I'd do, too, but since the OP didn't specify that he wanted a non-breaking space before the ellipsis, I didn't include one.
Doitsu is offline   Reply With Quote
Old 02-18-2014, 03:11 AM   #7
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,548
Karma: 19500001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Quote:
Originally Posted by cybmole View Post
i think , nitpicking here, gramatically, if there is no leading space, then you should not be adding one.
Assuming the source is correct, which I'd say is a risky assumption with ebooks

Quote:
Also, on an e-reader, I hate seeing the … appear on a new line all by itself, so I would add an   not a regular space.
I'd do that only at the end of a sentence, not if the ellipsis is somewhere in the middle.

Quote:
Originally Posted by Doitsu View Post
If the OP did that, he might end up with an ellipsis preceded by two spaces.
which, in any case, will not matter in HTML.
Jellby is offline   Reply With Quote
Old 02-18-2014, 04:14 AM   #8
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
Quote:
Also, on an e-reader, I hate seeing the … appear on a new line all by itself, so I would add an   not a regular space.
I'd do that only at the end of a sentence, not if the ellipsis is somewhere in the middle.

good point, tricky to automate, because there's often one follow ed by a closing speech mark, not a full stop e.g.

"and then he said, I bet this appears on a new line
... "
cybmole is offline   Reply With Quote
Old 02-18-2014, 08:26 AM   #9
Alt68er
Member
Alt68er began at the beginning.
 
Posts: 20
Karma: 10
Join Date: Dec 2013
Device: Pocketbook touch lux (623)
solved

Hi,
and first of all: many many thanks for your help and other comments.
In the meantime I found a solution which works absolutely fine for me:

Code:
find:    '\b\s{0,1}\.\.\.'
replace: ' …' or ' …'
The ' are used only to show exactly start and end of "code".

@ cybmole: You are right.
The most important rule is: the hellip is preceded by a blank when it replaces missing word(s), and not when it replaces missing letters of a word only.

In my case this doesn't matter because min. 99% of the 3 dots are replacing missing words.

Thanks again and have a nice day.
Peter
Alt68er is offline   Reply With Quote
Old 02-19-2014, 03:45 AM   #10
Hitch
Bookmaker & Cat Slave
Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.
 
Hitch's Avatar
 
Posts: 11,503
Karma: 158448243
Join Date: Apr 2010
Location: Phoenix, AZ
Device: K2, iPad, KFire, PPW, Voyage, NookColor. 2 Droid, Oasis, Boox Note2
Quote:
Originally Posted by Alt68er View Post

@ cybmole: You are right.
The most important rule is: the hellip is preceded by a blank when it replaces missing word(s), and not when it replaces missing letters of a word only.

In my case this doesn't matter because min. 99% of the 3 dots are replacing missing words.

Thanks again and have a nice day.
Peter
A space is grammatically required when an ellipsis is used to indicate a pause (not an abrupt break) in speech, as if the speaker trails off and then picks up again. E.g.:

"Well I told George ... I think I told George, that it was his turn."

This is a medial ellipsis. Normally, it's a terminal ellipsis (end of a sentence), but I've used it as it is far too often seen now, particularly when it's used improperly in lieu of an emdash. It's treated like a word; space before, space after.

However, in a terminal ellipsis, used to indicate not trailing-off speech, but the omission of material at the end of the quoted phrase/section:

"On the Thursday, the annual meeting will occur... ."

Between the last word of the quoted material and the ellipsis, there is no space. There is a space, just as if the ellipsis were a word itself, after the ellipsis. I've also, just for S&G's, included the dreaded "4th dot." The dreaded fourth dot is in actuality, of course, a period. Some style manuals advocate for the 4th dot; some argue against. That's a personal choice.

Most style manuals for non-fiction writing do agree that in non-fiction, ellipses for omitted material should actually be bracketed, e.g., [...] to show that they are indeed ellipses for that purpose.

Gosh, aren't you glad you posted about Regex for this? ;-)

Hitch
Hitch is offline   Reply With Quote
Old 02-19-2014, 04:06 AM   #11
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
Quote:
Originally Posted by Hitch View Post

"On the Thursday, the annual meeting will occur... ."


Gosh, aren't you glad you posted about Regex for this? ;-)

Hitch
I am used to seeing that example without the full stop i.e.
"On the Thursday, the annual meeting will occur... "

so a reader may line break before the closing quote - really , really ugly.
"On the Thursday, the annual meeting will occur...
"

with the full stop:

"On the Thursday, the annual meeting will occur...
."

OR

"On the Thursday, the annual meeting will occur... .
"

Last edited by cybmole; 02-19-2014 at 04:08 AM.
cybmole is offline   Reply With Quote
Old 02-19-2014, 04:36 AM   #12
Hitch
Bookmaker & Cat Slave
Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.
 
Hitch's Avatar
 
Posts: 11,503
Karma: 158448243
Join Date: Apr 2010
Location: Phoenix, AZ
Device: K2, iPad, KFire, PPW, Voyage, NookColor. 2 Droid, Oasis, Boox Note2
Cyb:

Yes, if you follow proper typographic conventions, but I confess right now to adding an nbsp prior to the ellipsis, for the same reasons you mention; I have a distaste for starting a line with an ellipsis if it's the trailing end of a sentence. And, yes, particularly on ADE, the trailing period and quotation mark CAN break apart. Of course, for that matter, I've seen ADE break between the period and the quotation mark, and ditto a question mark. Fugly, fugly, fugly.

Hitch
Hitch is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
search/replace multiline regex Alt68er Sigil 4 02-01-2014 09:40 AM
Regex search and replace dwlamb Sigil 6 04-12-2013 02:34 PM
regex search/replace Sharlene Sigil 10 01-28-2012 04:14 AM
Search & Replace/Regex help!! millertime13 Conversion 4 07-22-2011 02:40 AM
need regex help search and replace schuster Calibre 4 01-10-2011 09:00 AM


All times are GMT -4. The time now is 09:37 AM.


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