Extract part of a regex match

前端 未结 9 1956
北海茫月
北海茫月 2020-11-22 13:01

I want a regular expression to extract the title from a HTML page. Currently I have this:

title = re.search(\'.*\', html, re.IGNOR         


        
9条回答
  •  孤城傲影
    2020-11-22 14:00

    The provided pieces of code do not cope with Exceptions May I suggest

    getattr(re.search(r"(.*)", s, re.IGNORECASE), 'groups', lambda:[u""])()[0]
    

    This returns an empty string by default if the pattern has not been found, or the first match.

提交回复
热议问题