Quote:
Originally Posted by lindlind
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