title: How to replace <img> including class attribute "size-full" with <picture> element from post content WordPress using regular expression?
body: <p>I am developing my custom theme and trying to figure out how to modify the default code for WordPress <code>&lt;img&gt;</code> inserted into the post content, so I could add support for webP format and have it within <code>&lt;picture&gt;</code> element.</p>
  
  <p>I cannot get it working with regex.</p>
  
  <p>Currently, my post content has got  element to display the thumbnail within <code>&lt;p&gt;</code> tag, but the <code>&lt;img&gt;</code> tag is a link <code>&lt;a&gt;</code> which points to the full-size image.</p>
  
  <p>Currently I have got this for full-size image in the post content:</p>
  
  <pre><code>&lt;p&gt;
      &lt;a href="http://www.example.com/wp-content/uploads/2018/11/image-full.jpg" itemprop="url" title="Some title"&gt;
          &lt;img alt="Alt tag of the image" class="alignnone size-full" src="http://www.example.com/wp-content/uploads/2018/11/image-thumb.jpg" width="940" height="529"&gt;
      &lt;/a&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>I am trying to modify it to get this as result:</p>
  
  <pre><code>&lt;p&gt;
      &lt;a href="http://www.example.com/wp-content/uploads/2018/11/image-full.jpg" itemprop="url" title="Some title"&gt;
          &lt;picture&gt;
              &lt;source srcset="http://www.example.com/wp-content/uploads/2018/11/image-thumb.webp" type="image/webp" /&gt;
              &lt;img alt="Alt tag of the image" class="alignnone size-full" src="http://www.example.com/wp-content/uploads/2018/11/image-thumb.jpg" width="940" height="529"&gt;
          &lt;/picture&gt;
      &lt;/a&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>I have one or more images inserted like this. So, would need to check the whole post content and somehow modify/replace this by finding the  with class having "size-full" and then for them add  around?</p>
  
  <p>Should I use some <code>preg_replace()</code> or any function?</p>
  
  <p>Maybe using some filter?</p>
  
  <p>Do you have any ideas how to change it?</p>