View Single Post
Old 03-21-2024, 03:32 PM   #5
lomkiri
Zealot
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
Quote:
Originally Posted by lindlind View Post
string.replace('</span>\s*<br/>\s*', 'xx')
But it seems I cannot use \s or quantifiers in the function. Is there a way to do this?
\s, \s* etc. are part of the regex language, the python str.replace() does not understand them.
You'll have to import re or regex and use sub or match :
Code:
import regex
string = regex.sub(r'</span>\s*<br/>\s*', 'xx', string)
(calibre uses mainly the module regex, but you can get the help from the python module "re", regex is a superset of re : https://docs.python.org/3/library/re.html. You can also use re, if you prefer)

--------------

Edit (I haven't seen your last message when I posted this one) :
Quote:
additional note: I guess I should use something like re.sub instead, but is that possible?
Yes, it is possible. You can import in the function any module that is part of the calibre package, and re and regex are in this case.
You may see my other message of today to get a practical exemple

Last edited by lomkiri; 03-22-2024 at 04:20 AM. Reason: spelling corrections
lomkiri is offline   Reply With Quote