{"id":1835,"date":"2009-01-27T22:04:28","date_gmt":"2009-01-27T20:04:28","guid":{"rendered":"http:\/\/mummila.net\/nuudelisoppa\/?p=1835"},"modified":"2009-01-27T22:04:28","modified_gmt":"2009-01-27T20:04:28","slug":"a-php-regular-expression-to-look-for-unterminated-img-tags","status":"publish","type":"post","link":"https:\/\/mummila.net\/nuudelisoppa\/2009\/01\/27\/a-php-regular-expression-to-look-for-unterminated-img-tags\/","title":{"rendered":"A PHP Regular Expression To Look For Unterminated img Tags"},"content":{"rendered":"<p>After I had finally managed to craft this beast, I felt so proud that I just had to share it:<\/p>\n<blockquote><p><code>\/(&lt;img([^\\\/]|\\\/(?!&gt;))*)&gt;\/U<\/code><\/p><\/blockquote>\n<p>If I were to try and translate this into common language, it would perhaps go like this: after each occurrence of <code>&lt;img<\/code>, skip all non-<code>\/<\/code> characters, and also all occurrences of <code>\/<\/code> immediately followed by a <code>&gt;<\/code> \u2014 up until the next occurrence of <code>&gt;<\/code>. Unless you have a match at that point \u2014 a <code>&gt;<\/code> <em>without<\/em> an immediately preceding <code>\/<\/code> \u2014 move on to the next occurrence of <code>&lt;img<\/code>.<\/p>\n<p>And with each part of the expression in parenthesis, between quotation marks, following the corresponding translation: after each occurrence of <code>&lt;img<\/code>, skip all (&#8220;<code>*<\/code>&#8220;) non-<code>\/<\/code> characters (&#8220;<code>[^\\\/]<\/code>&#8220;), and also (&#8220;<code>|<\/code>&#8220;) all occurrences of <code>\/<\/code> immediately followed by a <code>&gt;<\/code> (&#8220;<code>\\\/(?!&gt;)<\/code>&#8220;) \u2014 up until the next occurrence of <code>&gt;<\/code>. Unless you have a match at that point \u2014 a <code>&gt;<\/code> <em>without<\/em> an immediately preceding <code>\/<\/code> \u2014 move on to the next occurrence of <code>&lt;img<\/code>.<\/p>\n<p>The outermost parentheses (<code>\/<strong>(<\/strong>&lt;img...<strong>)<\/strong>&gt;\/U<\/code>) grab the contents of the unterminated <code>&lt;img&gt;<\/code> tag apart from the closing angle bracket, so that it&#8217;s easy to pair with a &#8220;<code>&nbsp;\/&gt;<\/code>&#8221; to properly terminate it. Other parentheses are for defining subpatterns.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After I had finally managed to craft this beast, I felt so proud that I just had to share it: \/(&lt;img([^\\\/]|\\\/(?!&gt;))*)&gt;\/U If I were to try and translate this into common language, it would perhaps go like this: after each occurrence of &lt;img, skip all non-\/ characters, and also all occurrences of \/ immediately followed [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1835","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts\/1835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/comments?post=1835"}],"version-history":[{"count":0,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts\/1835\/revisions"}],"wp:attachment":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/media?parent=1835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/categories?post=1835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/tags?post=1835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}