![]() |
#1 |
Member
![]() Posts: 10
Karma: 10
Join Date: Jun 2012
Device: Kobo Touch
|
Search and replace question (regular expression)
Does the Search and replace function of Edit metadata allow one to conditionally insert text based on whether a capture group actually captured any text?
e.g. If I use the following regular expression in the Search for field (January)|(February)|(March)|(April)|(May)|(June)| (July)|(August)|(September)|(October)|(November)|( December) Can I insert the numeric value of the month by doing a conditional check to see which capture group actually captured text? I have the TextMate editor and this can be done there by using the following Replace with string: (?1:01)(?2:02)(?3:03)(?4:04)(?5:05)(?6:06)(?7:07)( ?8:08)(?9:09)(?10:10)(?11:11)(?12:12) The (?#:XXXX) construct means if group # matched, insert XXXX. Right now, I am having to do 12 separate searches to perform this task. Since I have to perform this particular search and replace on a recurring basis, it would be much easier to create a saved search and replace that performs all 12 replacements at once rather than having to do 12 separate replacements. Any help woud be greatly appreciated. |
![]() |
![]() |
![]() |
#2 |
Handy Elephant
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,737
Karma: 26785684
Join Date: Dec 2009
Location: Southern Sweden, far out in the quiet woods
Device: Samsung Galaxy Tab S8 Ultra
|
I think you can achieve what you require with the switch statement in a regexp used in a template.
There are examples of how this can be used to match different strings and insert another string, depending on the match. You can find some examples of this in the sticky thread "Techniques to use plugboards, custom columns and templates" in this subforum. Last edited by Adoby; 06-20-2013 at 07:30 AM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Member
![]() Posts: 10
Karma: 10
Join Date: Jun 2012
Device: Kobo Touch
|
Thanks. I'll look into that.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help with regular expression search/replace | bfollowell | Sigil | 12 | 06-20-2013 07:36 PM |
How to obtain a new page for every chapter in regular expression (search/replace)? | Ravenik | Conversion | 2 | 05-24-2012 07:04 AM |
Regular Expression: does not replace with spaces | murphycc | Conversion | 3 | 02-11-2012 01:31 PM |
Search & Replace - Regular expression | oldbwl | Calibre | 2 | 01-09-2011 09:33 AM |
Find/Replace with regular expression | hydrolith | Sigil | 6 | 03-01-2010 08:42 PM |