Your captured group requires youtu
inside, so the substring
[url]blahblah[/url] [url]www.youtube.com/blah[/url]
matches, because it starts with [url]
, includes youtu
, and ends with [/url]
.
Simply using a negated character set, excluding [
, probably isn't enough, because that wouldn't allow for nested tags to match, such as an input of
[url]foobar youtube[b]BOLD TEXT[/b][/url]
You might require negative lookahead for [/url]
right before each repeated character:
(?:(?!\[\/url\]).)*
Also, make sure that whatever comes after the [url
does not contain ]
s before coming to the true ]
, with:
\[url[^]]*\]
In full:
\[url[^]]*\]((?:(?!\[\/url\]).)*youtu(?:(?!\[\/url\]).)*)\[\/url\]
There's no need to make the quantifiers lazy anymore, because of the negative lookahead.
Demo:
https://regex101.com/r/hSAJEp/1