Quote:
Originally Posted by eschwartz
You have three ( ) commas in that template. Commas separate arguments in the function. re() takes three arguments -- val, pattern, replacement -- and the first is inferred as author_sort from the template. (val is only used in general and template program mode, not single-function mode which is what we are using here). You have also left args 1 & 3 empty.
|
There is another formula and had the same result:
ERROR
Of course, I read the manual. And did some help script on Python,
but still need help.
Why this template have an ERROR?
Spoiler:
Code:
# coding: utf-8
# if you have Python
# just run in terminal 'python re4calibre.py'
import re
print '\n'
print '\t For help use Online regex tester and debugger http://regex101.com/#python'
pattern = ur', ([^\s.])[^\s.]*(?:(?:$|\s|\.)+)'
replacement = ur', \1. '
str1 = u'Wood, Sir John & Vivekananda & Krisna, R. O. & Ball, Harry'
str2 = u'Wood, Sir & Warner, Brother'
str3 = u'Vivekanda & Shivananda'
str4 = u'Wood, Sir John & Vivekananda & McDonalds, G. B. & Warner, Brother & Braun'
str5 = u'Wood, Sir & McDonalds, Alex Jonathan'
print '\n'
print '\t1. '+str1+' -->'
print '\t '+re.sub(pattern, replacement, str1, flags=re.I)
print '\t2. '+str2+' -->'
print '\t '+re.sub(pattern, replacement, str2, flags=re.I)
print '\t3. '+str3+' -->'
print '\t '+re.sub(pattern, replacement, str3, flags=re.I)
print '\t4. '+str4+' -->'
print '\t '+re.sub(pattern, replacement, str4, flags=re.I)
print '\t5. '+str5+' -->'
print '\t '+re.sub(pattern, replacement, str5, flags=re.I)
print '\n'
print 'Copy template for Calibre column:'
print '{author_sort:re('+pattern+','+replacement+')}'
print '\n'