![]() |
#1 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 173
Karma: 40000
Join Date: Oct 2013
Device: kindle
|
Replacing with regex
EDIT: Solved
Let's say I want to replace all the occurrences of dash+digit, without a space, with dash space digit. I can use a regex to find what I look for (a very simple one: -[:alpha:], for example), but I don't know how to automatically insert a space. The issue of course is somehow "saving" that digit each time, "copying" it, and pasting it after inserting the space. I got a vague notion this could be done with javascript, but is there a simpler way? ty EDIT: Issue had already been solved, here. If I put the regex between (brackets) it saves the value it finds, which then I can paste by writing \1 in the "replace" field. So cool ![]() Last edited by 1v4n0; 01-09-2015 at 05:13 AM. |
![]() |
![]() |
![]() |
#2 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Quote:
![]() Also, great job with the edit. So often you see others say something along the lines of "found the answer," and they never post the solution! So when others stumble upon this topic, they have no clue! If you are just starting out with Regex, I would recommend looking through the Sticky Regex topic here for lots of examples: https://www.mobileread.com/forums/sho...d.php?t=167971 Anyway, this one is as easy as pie. What I would typically do is this: Search: -([0-9]) Replace: - \1 May I ask exactly what the use case is for adding a space between a dash and a number? The only thing I can think of with dashes and numbers is swapping hyphen -> en dash.... although maybe my mind is just too far up proper typography field. For example, I use this one all the time: Search: ([0-9])-([0-9]) Replace: \1–\2 So what this does is replaces "number" + "hyphen" + "number" with "number" + "en dash" + "number". This is the typographically correct way when dealing with years, or page numbers: 1910–1930 pp. 320–325 Last edited by Tex2002ans; 01-09-2015 at 05:45 AM. |
|
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 173
Karma: 40000
Join Date: Oct 2013
Device: kindle
|
Hmm what? What's the difference?
![]() Quote:
Whatever. I like this place ![]() |
|
![]() |
![]() |
![]() |
#4 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,909
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
|
![]() |
![]() |
![]() |
#5 | ||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
As theducks said. Especially in Regex, all three symbols mean VERY different things:
Quote:
In the "Filter" box, I just stick a hyphen. This will show you every single word with a hyphen in it. Then you can quickly scan the list and see if you spot any oddities. For example, things like "-the" or "-and" will almost NEVER be correct. So when you have a sentence like this: Quote:
![]() Depending on how many hyphens you have in your book, that could be another way to quickly go through and fix those types of errors. Edit: Oh wait, I think I see what you mean now. You are talking about "open spacing" around dashes. See: https://en.wikipedia.org/wiki/Dash Heh, at work, and all the books I work on at "closed spacing" (no spaces around the dashes). Saves me a bunch of headaches! ![]() Last edited by Tex2002ans; 01-09-2015 at 03:32 PM. |
||
![]() |
![]() |
Advert | |
|
![]() |
#6 |
mostly an observer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,518
Karma: 987654
Join Date: Dec 2012
Device: Kindle
|
I've always had this worrisome feeling that regex -- the very term! -- is beyond my payscale. Now that I see an example of regex in action, I know that I was right to be fearful.
|
![]() |
![]() |
![]() |
#7 | |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 173
Karma: 40000
Join Date: Oct 2013
Device: kindle
|
Quote:
Yeah, and also, "space dash word" does not appear in the spellcheck, at least not with perfectEpub. I'm learning a lot stuff here. Maybe someday someone will pay me for all the things I know ![]() |
|
![]() |
![]() |
![]() |
#8 | |||||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Quote:
Quote:
![]() The more you mess around with it, you just slowly will absorb more and more knowledge. Next thing you know, you will have lots of regexfu, and you will be up there with the masters! Quote:
Regular Expressions save me TONS of hours of work every single day, and it allows me to catch really obscure/hard typos, that otherwise would be quite hard to spot with just your naked eye (or old school Search/Replace). I have even caught hundreds of typos in books that have been professionally edited and then laid out by a pro typographer. (Working directly in code = way more granularity than at the GUI Word Processor/Typography programs). For example, in a similar vein as an accidental hyphen attached to a word, sometimes OCR causes accidental commas attached to a word: Quote:
Search: ([a-z]),([a-z]) Replace: \1, \2 or one that I catch ALL THE TIME in books is with page numbers accidentally attached to the "p.": Quote:
Replace: \1 \2 Regex also helps when you have to clean up a lot of abysmal code. For example, cleaning up all of the Calibre### classes, or the absolutely atrocious InDesign overrides. I don't know how I survived before I knew Regex! ![]() |
|||||
![]() |
![]() |
![]() |
#9 |
mostly an observer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,518
Karma: 987654
Join Date: Dec 2012
Device: Kindle
|
>Regex also helps when you have to clean up a lot of abysmal code. For example, cleaning up all of the Calibre### classes, or the absolutely atrocious InDesign overrides.
Well, at least I am spared those two needs! |
![]() |
![]() |
![]() |
#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:
Hitch |
|
![]() |
![]() |
![]() |
#11 |
mostly an observer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,518
Karma: 987654
Join Date: Dec 2012
Device: Kindle
|
Yes, $39.95 with a 90-day warranty. I suppose I should....
Thank you, Hitch. |
![]() |
![]() |
![]() |
#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
|
|
![]() |
![]() |
![]() |
Tags |
regex, search and replace, sigil |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Replacing your reader | jbcohen | General Discussions | 44 | 04-19-2012 01:54 PM |
Replacing code without replacing text? | ElMiko | Sigil | 6 | 11-30-2011 08:14 PM |
Replacing my PC with my Tab | wodin | Android Devices | 3 | 09-28-2011 02:20 PM |
Replacing my Hanlin V3 | maddz | Which one should I buy? | 0 | 11-25-2010 04:14 AM |
Replacing ¬ | PieOPah | Workshop | 5 | 12-17-2008 04:25 PM |