View Single Post
Old 11-25-2017, 09:50 AM   #2
gbm
Wizard
gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.gbm ought to be getting tired of karma fortunes by now.
 
Posts: 2,171
Karma: 8800000
Join Date: Jun 2010
Device: Kobo Clara HD,Hisence Sero 7 Pro RIP, Nook STR, jetbook lite
Quote:
Originally Posted by calmeilles View Post
I was trying to search with the regex "[A-Z][A-Z][A-Z]" — looking for 3 consecutive capital letters but the search operated case-insensitive so I was getting results ABC, AbC, abc etc which came as a considerable surprise.

I believe that this is because my install has LOCALE=en_GB and the collate order for that is case insensitive. I may be wrong, but it's my best guess and actually doesn't matter.*

The Regex documentation page includes how to make a case sensitive [which is what we'd normally expect] ignore case with the "(?i)" syntax but not how to do the reverse. It actually turned out quite a chore tracking down what was required and a note in the documentation I feel would be useful.

What I ended up with was

Code:
(?-i:[A-Z]{3})
It's the possibility of -i that's missing and was quite obscure even in the Python docs.

(*I am curious if this is true or something else caused it.
If my guess is right then also mentioning that LOCALE can serious affect your regexes would also be useful.)
If you are using the calibre ebook editor then all you needed to do was check the box for case sensitive.

bernie
Attached Thumbnails
Click image for larger version

Name:	Screenshot from 2017-11-25 09-49-27.png
Views:	287
Size:	99.5 KB
ID:	160220   Click image for larger version

Name:	Screenshot from 2017-11-25 09-59-03.png
Views:	264
Size:	88.2 KB
ID:	160222  

Last edited by gbm; 11-25-2017 at 10:00 AM. Reason: second screenshot added
gbm is offline   Reply With Quote