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

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 02-22-2012, 12:39 PM   #1
silentguy
Connoisseur
silentguy doesn't littersilentguy doesn't littersilentguy doesn't litter
 
Posts: 86
Karma: 200
Join Date: Nov 2010
Location: Dortmund, Germany
Device: Kindle PW2, Sony PRS-T1
Case Sensitive Regular Expression

Hi!
the manual stated that regular expressions in calibre are treated as case sensitive, but i noticed a few cases where this is not true. e.g. the re() function and the search.

Sadly python does not allow activating case sensitivity in a regexp, i.e. (?-i) does not work.

I'm mentioning this for two reasons. 1) Maybe the manual should be updated to reflect those changes and 2) it would be nice to somehow use case sensitive regexp. For templates I created my own function to do so, for searching it seems impossible. the search field does not even let me enter the same query with a different case. I know most of the time it's not needed but it would have been useful to me right now so I thought I'd mention it.
silentguy is offline   Reply With Quote
Old 02-23-2012, 05:03 AM   #2
chaley
"chaley", not "charley"
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: 6,849
Karma: 1918008
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by silentguy View Post
the manual stated that regular expressions in calibre are treated as case sensitive, but i noticed a few cases where this is not true. e.g. the re() function and the search.
Can you point at where this is said? It should be fixed, but a quick google search does not find where you are referring to.
Quote:
Sadly python does not allow activating case sensitivity in a regexp, i.e. (?-i) does not work.
This isn't python not working. Calibre sets the ignore case flag parameter on the call to re, which overrides any flags in the regexp.
Quote:
For templates I created my own function to do so, for searching it seems impossible. the search field does not even let me enter the same query with a different case. I know most of the time it's not needed but it would have been useful to me right now so I thought I'd mention it.
This has been discussed before. Allowing case sensitive would require changing to case sensitive or doing something very strange with embedded flags. The first won't happen, and working on the second one (and dealing with the fallout) isn't something that interests me. Perhaps you could take it on.
chaley is offline   Reply With Quote
 
Advertisement
Old 02-23-2012, 04:27 PM   #3
silentguy
Connoisseur
silentguy doesn't littersilentguy doesn't littersilentguy doesn't litter
 
Posts: 86
Karma: 200
Join Date: Nov 2010
Location: Dortmund, Germany
Device: Kindle PW2, Sony PRS-T1
I created an emergency solution for myself, just in case, that I'm currently not using but in case someone else wants something like this: i created template functions for contains and re that are case sensitive (mainly just removing the flag from the predefined ones) and then if i need to search something case sensitive, i use the custom column as a flag. not elegant, seems slower, but works...

I was talking about http://manual.calibre-ebook.com/regexp.html, it talks extensively about regex being case sensitive and how to switch it of, etc.

All in all I agree, best to just leave it case insensitive, to few use cases to put work into it
silentguy is offline   Reply With Quote
Old 05-11-2015, 05:10 AM   #4
rebl
Connoisseur
rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.
 
Posts: 61
Karma: 560010
Join Date: Mar 2010
Device: Kindle 5 NT
so how do i search for lowercase authors?

If case sensitive search does not work (calibre 2.27) then how can we search for e.g. authors in lowercase?
I need to do this because I have a few imported books that have the title and author swapped and this is a very easy way of finding them.
I've tried ^[a-z] or even ^m as a test and it returns all authors or, respectivelly or authors starting with M.

Edit:
Unfortunatelly, the solution posted by silentgy does not appear to work either.

{author:switch(^[a-z], az, )} by which I was trying to identify lowercase authors fills the column for all books with "az" even for the authors who's names start with [A-Z]

also confirmed here:
http://manual.calibre-ebook.com/template_lang.html
Many functions use regular expressions. In all cases, regular expression matching is case-insensitive.

edit2: ok there are a few functions that can work for what I'm trying; I will also test with re()

edit3: there is another problem with re() - the manual give two versions of the syntax (with 2 or 3 arguments) and only the 2 version is correct

Here (http://manual.calibre-ebook.com/temp...rn-replacement) the syntax is described as:
re(val, pattern, replacement) – return the field after applying the regular expression. All instances of pattern are replaced with replacement. As in all of calibre, these are python-compatible regular expressions

but here (http://manual.calibre-ebook.com/template_lang.html)
is:
re(pattern, replacement) – return the field after applying the regular expression. All instances of pattern are replaced with replacement. As in all of calibre, these are python-compatible regular expressions.

I know I have an auther named e.g. "time" (with no quotes).
first version (with three arguments) outputs a template error (incorrect number of arguments)
i've tried with {author:re(^t, t, zzz)} and with {author:re(^[a-z], az, zzz)}
second version {author:re(^t, t)} just copies all the authors in the custom column
(because it replaces T or t with T or t)
while {author:re(^[a-z], az, zzz)} replaces any first character with az but it is not case sensitive

so... no case sensitive search by no means?

Last edited by rebl; 05-11-2015 at 05:54 AM.
rebl is offline   Reply With Quote
Old 05-11-2015, 05:48 AM   #5
chaley
"chaley", not "charley"
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: 6,849
Karma: 1918008
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by rebl View Post
edit2: ok there are a few functions that can work for what I'm trying; I will also test with re()
All of the builtin template re functions ignore case.

Silentguy created custom template functions to do what he wanted. You could do the same.

The quality check plugin might already do what you want.
chaley is offline   Reply With Quote
Old 05-11-2015, 05:56 AM   #6
rebl
Connoisseur
rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.rebl ought to be getting tired of karma fortunes by now.
 
Posts: 61
Karma: 560010
Join Date: Mar 2010
Device: Kindle 5 NT
Quote:
Originally Posted by chaley View Post
All of the builtin template re functions ignore case.

Silentguy created custom template functions to do what he wanted. You could do the same.

The quality check plugin might already do what you want.
Oh, I was editing my message meanwhile and doing those tests
Thank you chaley. I guess at first I didn't get the proper meaning of "custom" function...
I will check the quality check plugin, thank you again for taking the time to reply.
rebl 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
Regular Expression Help Azhad Calibre 86 09-27-2011 02:37 PM
Regular Expression Help iKarampa Calibre 13 12-15-2010 07:17 AM
Regular expression help krendk Calibre 4 12-04-2010 04:32 PM
Regular Expression Help smartmart Calibre 5 10-17-2010 05:19 AM
Help with the regular expression Dysonco Calibre 9 03-22-2010 10:45 PM


All times are GMT -4. The time now is 06:08 PM.


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