Hello! There is a text. How can I select YouTube video links from it? For example, $ text = "This is a cool YouTube video: http://www.youtube.com/watch?v=cfYDc-yafbM";

    2 answers 2

    Using a regular expression, for example: ^ http: \ / \ / (?: www.)? Youtube.com \ / watch \? (? = [^?] * V = \ w +) (?: [^ \ S? ] +)? $

      Regular expression. Make a mask by which you will determine whether this video is from YouTube or not.