0

i have a script that search match but i think that this way not is the best because is so long, i know that maybe it can be more short but i don't know much things about regexp.

I need get all string that start with http but also i need get if inside string contain youtube.com or youtu.be and i created this regexp:

^(?=.*\bhttp)(?=.*\byoutube\.com\b).*$|^(?=.*\http)(?=.*\byoutu\.be\b).*$

but i guess that maybe something like it work:

^(?=.*\bhttp)(?=.*\byoutube\.com\b|\byoutu\.be\b).*$
SonickSeven
  • 437
  • 1
  • 4
  • 19
  • `/https?:\/\/\S*?youtube\.(?:be|com)/i` is going to fail to match `youtu.be` – ionizer Mar 11 '20 at 17:33
  • @ionizer: You're right. I overlooked 2nd part. Regex should be: `/https?:\/\/\S*?(?:youtube\.com|youtu\.be)/i ` – anubhava Mar 11 '20 at 17:35
  • I think that looks like the answers found in Mr. Polywhirl's comment, and I think we just needed to add the `http` part to be required. Though specific to this question, regex like these should be enough: `/^(http:\/\/)(youtube\.com|youtu\.be)\/?/i`, unless you want more optimized ones... – ionizer Mar 11 '20 at 17:45

0 Answers0