How can I autogenerate a case insensitive REGEXP for a string that may have the case following variations:
‘ENTI’, ‘Enti’
I got this so far but it looks clumsy,
entity_type = 'Enti'
prefix = 'E'
for char in entity_type[1:]:
logs_prefix += '[' + char.upper() + char.lower() + ']'
print logs_prefix
>>>'E[Nn][Tt][Yy]'
My goal is to initially discover the list of active logs (the rotated ones will be ending with a timestamp) which start with a given case insensitive sequence, so I can
regexp_filters = logs_prefix + '_A.out'
command = "ssh %(user)s@%(ip)s 'cd %(source_path)s; ls -t %(regexp_filters)s'" % locals()
and generate different rsync expressions for a range of hosts.
Ignore the exclude, its made of several –excludes witholder, crashed ‘*_A.out’ logs
sync = "rsync -e ssh -a %(remote_rsync_binary)s --compress=9 -pgtov %(excluded_expression)s %(filters_expression)s --exclude='*' %s(user)@%(ip)s:%(source_path)s%(file_filter)s %(target_path)s" % locals()
Minor question, how to easily enclose a string/char with other chars,
in this case:
[char]
EDIT :
Found a cleaner solution, is there a better way?
for char in entity_type[1:]:
prefix += "[%s]" % "%s%s" % (char.upper(), char.lower() )
EDIT2: (improvement)
as @eyquem wrote,
prefix + ''.join( "[%s%s]" % (char.upper(), char.lower() for char in entity_type[1:])
Try this: