![]() |
#1 |
Member
![]() 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 |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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: … |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 "..."
|
![]() |
![]() |
![]() |
#4 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#5 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,727
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
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. |
|
![]() |
![]() |
![]() |
#7 | ||
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,548
Karma: 19500001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
![]() Quote:
which, in any case, will not matter in HTML. |
||
![]() |
![]() |
![]() |
#8 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 ... " |
![]() |
![]() |
![]() |
#9 |
Member
![]() 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 ' …' @ 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 |
![]() |
![]() |
![]() |
#10 | |
Bookmaker & Cat Slave
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
"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 |
|
![]() |
![]() |
![]() |
#11 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
Quote:
"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. |
|
![]() |
![]() |
![]() |
#12 |
Bookmaker & Cat Slave
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |