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

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 02-25-2012, 05:57 PM   #1
Sidetrack
Enthusiast
Sidetrack began at the beginning.
 
Posts: 39
Karma: 10
Join Date: Jan 2009
Location: South Pacific
Device: Kindle DX
Regex help needed, selecting single tags out of namy

I'm having some trouble, I have a number of tags all prefixed with "QC: " that I'd like to extract from the tags column and dump into a custom tags column.

I can get at the tags I want just fine with (^QC[:] [^,]*) but I can't seem to come up regex to exclude the preceding and following tags so I can dump only the QC tags into the custom column.

Any ideas? I'd really rather not apply them one at a time from the edit metadata interface.
Sidetrack is offline   Reply With Quote
Old 02-25-2012, 08:10 PM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,659
Karma: 54369090
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by Sidetrack View Post
I'm having some trouble, I have a number of tags all prefixed with "QC: " that I'd like to extract from the tags column and dump into a custom tags column.

I can get at the tags I want just fine with (^QC[:] [^,]*) but I can't seem to come up regex to exclude the preceding and following tags so I can dump only the QC tags into the custom column.

Any ideas? I'd really rather not apply them one at a time from the edit metadata interface.

Assume this is in Search and replace

<not tested>
Matches anything up to your term, your term, matches anything after your term

(.*)your search term(.*)

the replace into destination column: \2
theducks is offline   Reply With Quote
Advert
Old 02-26-2012, 05:00 AM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,691
Karma: 6240117
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Note that searching multiple fields like tags does a search tag by tag. If a search does not match, the value is not touched.

If you want to search tags (which will probably work best), then you must get fancy with the search expression so that it always matches the entire tag. Try
Code:
^(QC[:] .*|).*?$
This expression ensures that \1 either contains the complete tag or the empty string.

You can avoid the multiple-item processing by using "template" as the source field and "{tags}" as the template. In this case something like your expression would work, but you must not use the anchor to take care of the case where QT is not the first tag. In addition, it would probably be easier to remove the unwanted tags than to reconstruct the list of wanted tags.
chaley is offline   Reply With Quote
Old 02-26-2012, 09:49 PM   #4
Sidetrack
Enthusiast
Sidetrack began at the beginning.
 
Posts: 39
Karma: 10
Join Date: Jan 2009
Location: South Pacific
Device: Kindle DX
Quote:
Originally Posted by theducks View Post
Assume this is in Search and replace

<not tested>
Matches anything up to your term, your term, matches anything after your term

(.*)your search term(.*)

the replace into destination column: \2
Yes it is in Seach and Replace. That is the method I tried and it doesn't seem to work with multiple tags.
Sidetrack is offline   Reply With Quote
Old 02-26-2012, 10:24 PM   #5
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,659
Karma: 54369090
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by Sidetrack View Post
Yes it is in Seach and Replace. That is the method I tried and it doesn't seem to work with multiple tags.
Chaley pointed out (and he really in the know here) that tags are really multiple single items (records in the DB).
theducks is offline   Reply With Quote
Advert
Old 02-26-2012, 10:54 PM   #6
Sidetrack
Enthusiast
Sidetrack began at the beginning.
 
Posts: 39
Karma: 10
Join Date: Jan 2009
Location: South Pacific
Device: Kindle DX
Using the {tags} template worked wonderfully. Removing tags will be no problem, if search and replace won't do the trick I don't mind removing them manually.
Sidetrack 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
restricting regex to single lines of code? ElMiko Sigil 14 01-28-2012 04:39 PM
Help with regex needed. kamanza Library Management 3 01-24-2012 07:27 AM
RegEx Help needed ghostyjack Sigil 14 11-02-2011 10:22 AM
Regex help needed gandor62 Calibre 2 11-04-2009 10:27 AM
Help needed in selecting a mobile reader jdedecker Which one should I buy? 0 03-29-2009 08:59 AM


All times are GMT -4. The time now is 10:53 PM.


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