0

I am struggling with a regex.

I would like to match the height of the sl-block for a given image. In the example I have two images, image1.png and image2.png.

When I use a lookbehind it always match the very first height, but I would like to match the one corresponding to the sl-block where the image lays.

Using the code in the example, the regex should return 300.45678 if image1.png is chosen, and 300 for image2.png.

<div class="sl-block" data-block-type="img" style="width: 600px; height: 300.45678px; left: 0px; top: 0px;" data-name="img-b59ef5">
  <div class="sl-block-content" style="z-index: 11;">
    <img seamless="" scrolling="no" width="600" height="400" frameborder="0" src="/static/revealjs/img/test_size/image1.png" data-lazy-loaded="">
  </div>
</div>
<div class="sl-block" data-block-type="img" style="width: 600px; height: 300px; left: 0px; top: 0px;" data-name="img-b59ef5">
  <div class="sl-block-content" style="z-index: 11;">
    <img seamless="" scrolling="no" width="600" height="400" frameborder="0" src="/static/revealjs/img/test_size/image2.png" data-lazy-loaded="">
  </div>
</div>
Michal
  • 13
  • 1
  • Using regular expressions is not the right way of parsing HTML -- you should be using an HTML parser instead. Also, you haven't shown what you have tried so far. – Ruslan Osmanov Aug 14 '20 at 13:26
  • 4
    Must read for you: [TH̘Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ](https://stackoverflow.com/a/1732454/3600709) – ctwheels Aug 14 '20 at 14:03
  • Anyway with regex it's super ugly (and highly not recommended - don't use this), but here you go: https://regex101.com/r/32IdMK/1 - change `image1` to `image2` to get image2 instead. – ctwheels Aug 14 '20 at 14:09
  • Thank you very much @ctwheels!! @RuslanOsmanov, I've tried something you would prefer not seeing – Michal Aug 14 '20 at 15:01

0 Answers0