Match all youtube links in a string of text
[^\s] is effectively just \S
For checking against youtu.be links, you can have:

youtu(\.be|be\.com)

If you do not want to store every matched group, use (?:...)
[A-Za-z0-9_] can be simplified to \w.
Use a different delimiter than / so that you won't have to escape it in pattern.


Therefore:

preg_match_all(
    '@(https?://)?(?:www\.)?(youtu(?:\.be/([-\w]+)|be\.com/watch\?v=([-\w]+)))\S*@im',
    $this-&gt;content,
    $matches
)