我需要从列表中过滤掉以下内容:
^[^\w ]$
'^\n( )*$' (\n at the beginning followed by spaces)
'^\n( )*\n$' (\n at both ends with spaces)
'^[]$' (space alone)
如何将它们组合成一个表达式?
答案 0 :(得分:1)
尝试:
r1 ='^[^\w ]'
r2 ='^\n( )*'
r3= '^\n( )*\n'
r4 = '^\n( )*\n'
string="(\n at the beginning followed by spaces)"
generic_re = re.compile("(%s|%s|%s|%s)" % (r1, r2, r3, r4)).findall(string)