print start of html tags

后端 未结 2 2038
执笔经年
执笔经年 2021-01-28 21:30

I want to print out the first html tags thats has attributes

    

test

test2

2条回答
  •  花落未央
    2021-01-28 22:01

    You should use a non-greedy match for any number of characters to the left of the =, so:

    r'<.*?=.*?>'
    

    That will match a <, followed by a minimum number of characters, followed by a =, followed by the minimum number of characters until the >.

    What you had:

    r''
    

    Means an optional <, followed by a =, followed by any string going up to the >. Since the < is optional and would only match if right before the =, you end up with no matches for it.

提交回复
热议问题