Fix invalid self-closed HTML tags

spiros

  • Administrator
  • Hero Member
  • *****
    • Posts: 812034
    • Gender:Male
  • point d’amour
Fix invalid self-closed HTML tags

Mediawiki category: Pages using invalid self-closed HTML tags (this is created automatically). Fix with this regex:

// Find every tag that isn't the first set of key words and starts with a set of letters. Capture the tag name and attribute
Code: [Select]
<(?!area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)([a-z|A-Z|_|\-|:|0-9]+)([^>]*)/>
// Create a new tag using the original tag name (i.e. the first capture group of ([a-z|A-Z]*))
// Then add the attributes (i.e. second capture group of (.*))
// Then create a close tag using the first capture group
Code: [Select]
<$1$2></$1>
https://www.reddit.com/r/regex/comments/6mpc7b/replace_invalid_selfclosing_nonvoid_html_tags/
« Last Edit: 03 Oct, 2019, 16:24:48 by spiros »


 

Search Tools