Regex: Strip HTML attributes except SRC

前端 未结 6 942
予麋鹿
予麋鹿 2020-12-16 17:13

I\'m trying to write a regular expression that will strip all tag attributes except for the SRC attribute. For example:

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-16 17:43

    Alright, here's what I used that seems to be working well:

    <([A-Z][A-Z0-9]*)(\b[^>src]*)(src\=[\'|"|\s]?[^\'][^"][^\s]*[\'|"|\s]?)?(\b[^>]*)>
    

    Feel free to poke any holes in it.

提交回复
热议问题