0

I have this code and works correctly but I'm wondering if it can be optimized to not repeat the formats in capitalize & lowercase (?:mp4|MP4|webm|WEBM|mov|MOV|ogg|OGG))

$post[message] = preg_replace('/<a href="(.+?\.(?:mp4|MP4|webm|WEBM|mov|MOV|ogg|OGG))" target="_blank">(.+?)<\/a>/', '<video controls="" src="$1" style="max-width: 640px; max-height: 360px;outline:none;" loop>VIDEO HTML5</video>', $post[message]);
Akirabyte
  • 9
  • 5
  • 1
    Does this answer your question? [Regex: ignore case sensitivity](https://stackoverflow.com/questions/9655164/regex-ignore-case-sensitivity) – Mister Someone Oct 27 '20 at 15:34
  • In place of `.+?`, better to use `[^"]+`. – Casimir et Hippolyte Oct 27 '20 at 16:07
  • Thank you for the sugestion, I would like to know why is better? – Akirabyte Oct 27 '20 at 16:41
  • 1. you are sure that it doesn't match outside of the attribute value. 2. a greedy quantifier is faster since it reaches quickly the end of the attribute and backtracks only 4 times to be able to check the extension subpattern. (a lazy quantifier has to check this subpattern from the start of the attribute for each character until the end (-4 characters)). – Casimir et Hippolyte Oct 27 '20 at 19:35
  • Thank you very much for the tip and explanation :) – Akirabyte Oct 31 '20 at 07:10

0 Answers0