Regular expression to match one of two video ID's in a Google Video URL

Posted by Baldur on Stack Overflow See other posts from Stack Overflow or by Baldur
Published on 2010-05-13T18:27:32Z Indexed on 2010/05/13 18:54 UTC
Read the original article Hit count: 308

Filed under:
|
|
|

I need to grab the video ID from a Google Video URL. There are two different types of URLs that I need to be able to match:

http://video.google.com/videoplay?docid=-3498228245415745977#

where I need to be able to match -3498228245415745977 (note the dash; -), and

video.google.com/videoplay?docid=-3498228245415745977#docid=2728972720932273543

where I need to match 2728972720932273543. Is there any good regular expression that can match this?

This is what I've got so far: @"docid=(-?\d{19}+)" since the video ID seems to be 19 characters except when it's prefixed with the dash.

I'm using C# (of which I have very little experience) if that changes anything.

P.s. I would also appreciate you review my regular expressions for YouTube (@"[\?&]v=([^&#])";), RedTube (@"/(\d{1,6})") and Vimeo (@"/(\d*)").

I do not expect users to enter the full URL and thus do not match the ^http://\\.?sitename+\\.\\w{2,3}.

© Stack Overflow or respective owner

Related posts about regex

Related posts about match