Regular expression syntax for “match nothing”?

前端 未结 6 904
清酒与你
清酒与你 2021-01-31 00:58

I have a python template engine that heavily uses regexp. It uses concatenation like:

re.compile( regexp1 + \"|\" + regexp2 + \"*|\" + regexp3 + \"+\" )
<         


        
6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 01:39

    Or, use some list comprehension to remove the useless regexp entries and join to put them all together. Something like:

    re.compile('|'.join([x for x in [regexp1, regexp2, ...] if x != None]))
    

    Be sure to add some comments next to that line of code though :-)

提交回复
热议问题