Regular expression to remove images that contain an inline-style height range

0

How could I improve this regular expression to remove images that range from 29 to 45: [0-9]{29, 45} ?

My expression:

<img.+?(style=\".+?height:(29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45)%;.+?\")[^>]*>

When I tried to do so it removed the style of the image and not the image itself:

 <img.+?(style=\".+?height:([0-9]{29, 45})%;.+?\")[^>]*>

See my example:

link

    
asked by anonymous 10.11.2017 / 14:09

1 answer

2

Because your range is from 29 to 45 or is relatively regular, the logic would be as follows:

  • Separate decimals and units
  • Check the rang of each of them
  • Decimal: [2-4] , unit: [0-9] = > \d

However the exception is 29 and 45, so:

  • Decimal 2, unit 9.
  • Decimal 4 has [0-5]

Then the rule would be:

29|3\d|4[0-5]

Full REGEX E:

<img.+?(style=\".+?height:(29|3\d|4[0-5])%;.+?\")[^>]*>

As for {29, 45}

This is actually a repeating interval and not a number allowed, for my details you can see Quantifiers

p>     
10.11.2017 / 14:22