Regex / pipe string extraction help


Need to return a substring between two specified strings.

I have this excerpt from an XML url.

<div class="hs-featured-image-wrapper"> <a href="" title="" class="hs-featured-image-link"> <img src="" alt="image1 copy 2.png" class="hs-featured-image" style="width:auto !important; max-width:50%; float:left; margin:0 15px 15px 0;"> </a> </div> <p><span style="font-weight: 400;">Getting ready to garden? Here are some tips to ensure that this year’s garden is a success.</span></p>

I need to return the img src and the actually description that is merged with all this formatting

here is what I have so far…

        {{entry.getElementsByTagName('description')[0].textContent | regexp() }}<br><br>

I was using SLICE, but i need to get the string between two specific strings instead of the indexes.


I think you would be better off using an XML parser library. Regular expressions are not capable of doing this robustly.


thanks. i will try to look into that. do you have any specific examples?


Figured it out!! I ended up implementing a custom pipe to filter out the unneeded text/tags.

transform(value: string, …args) {
return value.split(‘Starting string to remove from behind’).pop().split(‘ending string to remove from after’).shift();

works for something like this…