Sign in to follow this  
Followers 0
FireFox

Check a youtube url with stringregexp

12 posts in this topic

#1 ·  Posted (edited)

Hi,

Everything is in the title, here is the different youtube urls i know, If you've got more then tell me :unsure:

http://www.you tube.com/watch?v=videoid << remove the space
http://www.youtube.com/embed/videoid
http://youtu.be/videoid

If you can not make one regexp because the short youtube url is verry different from the others, you can make two regexps.

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites



No, everything is not in the title. Actually, very little is in the title (or body) of the OP.

What does "Check" mean? Check for what?

What have you tried? Post a short symptom reproducer script.

Given your example input URLs, what were you looking for from each by way of a RegExp?

:unsure:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

In order to get any decent help with RegExps you need to show us the possible input values and the output that you expect from each one.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

In order to get any decent help with RegExps you need to show us the possible input values and the output that you expect from each one.

I though I had enough explained, anyway.

I'm crap with regexp so I havn't got it working at all.

I want to know if the string is a valid youtube video url, and I think the most efficient way is to do it with regexp.

Here is the possibilities : (remove the spaces)

http://www. youtube.com/watch?v=wagn8Wrmzuc
http://www. youtube.com/watch?v=wagn8Wrmzuc&feature=player_embedded
http://youtu.be/wagn8Wrmzuc
http://www.youtube.com/embed/wagn8Wrmzuc

FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

So, list your rules for YouTube validity. Once you do that clearly, implementing the rules in code is the easy part. If the rules are vague (or non-existent as we have here), then no amount of code can help you.

:unsure:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If StringRegExp($sStr, "(?m:^)(http://[w.]*youtu\.?be[.com]*/.+)(?:\v|$)+") Then
    $sValid = " valid"
Else
    $sValid = " not valid"
EndIf

MsgBox(0, "Result", $sStr & @CRLF & "is " & $sValid)

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Glad it worked and infact there was no real reason why it should based on the information you gave us. Don't blame anyone if it fails at some point.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Glad it worked and infact there was no real reason why it should based on the information you gave us. Don't blame anyone if it fails at some point.

yep, it doesn't work in some cases, I will try to explain exactly what I want :

The only thing which can change in the url is the video ID, for example in your example if I remove the dot before "com" it will say that the link is valid but it's not the case.

Between [ ], the string must be the same or the url will be invalid :

[http://www.youtube.com/watch?v=]wagn8Wrmzuc
[http://www.youtube.com/watch?v=]wagn8Wrmzuc&feature=player_embedded
[http://youtu.be/]wagn8Wrmzuc
[http://www.youtube.com/embed/]wagn8Wrmzuc

FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Am a bit rusty on some Regex, but throwing in an attempt...

Global $aURLs[5] = ["http://www.youtube.com/watch?v=wagn8Wrmzuc", _
                "http://www.youtube.com/watch?v=wagn8Wrmzuc&feature=player_embedded", _
                "http://www.youtubecom/watch?v=wagn8Wrmzuc", _
                "http://youtu.be/wagn8Wrmzuc", _
                "http://youtube.com/embed/wagn8Wrmzuc"]

For $sStr In $aURLs

    If StringRegExp($sStr, "http://(?:www\.)?youtu(?:\.be/|be\.com/(?:embed/|watch\?v=))[^&%\v+?].*") Then
        ConsoleWrite("VALID! - " & $sStr & @CRLF)
    Else
        ConsoleWrite("NOT VALID! - " & $sStr & @CRLF)
    EndIf

Next

Share this post


Link to post
Share on other sites

#10 ·  Posted

yep, it doesn't work in some cases, I will try to explain exactly what I want :

The only thing which can change in the url is the video ID, for example in your example if I remove the dot before "com" it will say that the link is valid but it's not the case.

Between [ ], the string must be the same or the url will be invalid :

[http://www.youtube.com/watch?v=]wagn8Wrmzuc
[http://www.youtube.com/watch?v=]wagn8Wrmzuc&feature=player_embedded
[http://youtu.be/]wagn8Wrmzuc
[http://www.youtube.com/embed/]wagn8Wrmzuc

FireFox.

hi FireFox,

here's my shot at it,

#include <Array.au3>

$matchArr = StringSplit("Invalid,Valid", ",", 2)
$RegExp="(?i)^http://((www\.)?youtube\.com/(watch\?v=|embed/)|youtu\.be/)[a-z0-9_]{11}($|&[a-z0-9_=&]*)"

Dim $testArray[10][2]
$testArray[0][0] = "http://www.youtube.com/watch?v=wagn8Wrmzuc"
$testArray[1][0] = "http://www.youtu.be/wagn8Wrmzuc"
$testArray[2][0] = "http://youtube.com/watch?v=wagn8Wrmzuc"
$testArray[3][0] = "http://youtu.be/wagn8Wrmzuc"
$testArray[4][0] = "http://www.youtube.com/watch?v=wagn8WrmzucR"
$testArray[5][0] = "http://.youtube.com/watch?v=wagn8Wrmzuc"
$testArray[6][0] = "http://www.youtube.com/watch?v=wagn8Wrmzuc&feature=player_embedded"
$testArray[7][0] = "http://www.youtue.com/watch?v=wagn8Wrmzuc"
$testArray[8][0] = "http://youtube.com/embed/wagn8Wrmzuc"
$testArray[9][0] = "shttp://www.youtube.com.watch?v=wagn8Wrmzuc"

For $i = 0 To 9
    $testArray[$i][1] = $matchArr[StringRegExp($testArray[$i][0],$RegExp)]
Next

_ArrayDisplay($testArray)

Hope this helps

-smartee

Am a bit rusty on some Regex, but throwing in an attempt...

Global $aURLs[5] = ["http://www.youtube.com/watch?v=wagn8Wrmzuc", _
                "http://www.youtube.com/watch?v=wagn8Wrmzuc&feature=player_embedded", _
                "http://www.youtubecom/watch?v=wagn8Wrmzuc", _
                "http://youtu.be/wagn8Wrmzuc", _
                "http://youtube.com/embed/wagn8Wrmzuc"]

For $sStr In $aURLs

    If StringRegExp($sStr, "http://(?:www\.)?youtu(?:\.be/|be\.com/(?:embed/|watch\?v=))[^&%\v+?].*") Then
        ConsoleWrite("VALID! - " & $sStr & @CRLF)
    Else
        ConsoleWrite("NOT VALID! - " & $sStr & @CRLF)
    EndIf

Next

Your code mistakes some of my invalid urls to be valid, you should indicate the expressions' start and end, and www.youtu.be/... shouldn't be valid :unsure:

Hope this helps :>

Share this post


Link to post
Share on other sites

#11 ·  Posted

Your code mistakes some of my invalid urls to be valid, you should indicate the expressions' start and end, and www.youtu.be/... shouldn't be valid :unsure:

Hope this helps :>

Good catch, thanks. I did forget to specify start and end and I didn't realize that youtu.be didn't work with the www, never thought to check.

Think your expression covers it all though.

Share this post


Link to post
Share on other sites

#12 ·  Posted

Your code mistakes some of my invalid urls to be valid, you should indicate the expressions' start and end, and www.youtu.be/... shouldn't be valid :unsure:

I didn't know that, you made a very good work ! Posted Image

@smartee, @bwochinski

Thanks both for your help :>

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0