我怎样才能自动生成的字符串大小写不敏感REGEXP,可能有情况如下变化: “ENTI”,“ENTI”Python的 - 产生不区分大小写REGEXP像串
我得到了这个到目前为止,但它看起来笨拙,
entity_type = 'Enti'
prefix = 'E'
for char in entity_type[1:]:
logs_prefix += '[' + char.upper() + char.lower() + ']'
print logs_prefix
>>>'E[Nn][Tt][Yy]'
我的目标是最初发现活动日志(在旋转的将一个时间戳结束),这与给定的情况下,不敏感序列启动列表中,这样我就可以
regexp_filters = logs_prefix + '_A.out'
command = "ssh %(user)[email protected]%(ip)s 'cd %(source_path)s; ls -t %(regexp_filters)s'" % locals()
并为一系列主机生成不同的rsync表达式。 忽略排除,它提出了一些--excludes witholder的,坠毁“* _A.out”日志
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()
次要问题,如何轻松地在这种情况下附上与其他字符的字符串/字符, : [炭]
编辑: 发现一个清洁的解决方案,是有更好的方法?
for char in entity_type[1:]:
prefix += "[%s]" % "%s%s" % (char.upper(), char.lower())
EDIT2:(改善) 作为@eyquem写道,
prefix + ''.join("[%s%s]" % (char.upper(), char.lower() for char in entity_type[1:])
难道你不能忽略大小写吗? – nevets1219 2011-05-10 18:32:56
编号 目标是自动发现与远程路径中的给定模式相关的日志(存在一些变体), 生成REGEX字符串并将其提供给rsync命令。 – 2011-05-10 18:35:21
也许你还应该发布你的数据以及预期的结果 – schoetbi 2011-05-10 18:36:25