Jump to content

How to extract YouTube links from random text.


DJKMan
 Share

Recommended Posts

I know I need to use regular expression to do this. I'm not quite that good with regular expression yet.

I've read some articles and it appears no one has found an official solution for the dynamic youtube links.

Here's an example:

some text and then some text

Note: I grabbed these links from the example forums that have attempted to use regular expression to achieve this. I never really looked at the vids (it's not important).

 

 

Link to comment
Share on other sites

DJKMAN,

This should work for you :mellow:

Dim $searchString = "some text http://www.youtube.com/watch?v=szygGmDsAl4&search_query=testing&search=Search and then some text" ; This could be a file

If FindYT($searchString) Then
    MsgBox(0, @ScriptName, "I found a YouTube link!")
Else
    MsgBox(0, @ScriptName, "No YouTube link :(")
EndIf

Func FindYT($ioString)
    Local $RegEx = "(http://www.youtube.com)?/(v/([-|~_0-9A-Za-z]+)|watch\?v\=([-|~_0-9A-Za-z&=]+)?.*?)"
    If StringRegExp($ioString, $RegEx) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

James

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...