Regex in c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nightcrawler

    #1

    Regex in c#

    I am building a web page where people can link in a youtube video by
    copying and pasting the link that is provided by youtube. How can I
    use a regular expression to capture the URL only from the link below:

    <object width="425" height="355"><p aram name="movie" value="http://
    www.youtube.com/v/xSqNx7vJLDE&rel =1"></param><param name="wmode"
    value="transpar ent"></param><embed src="http://www.youtube.com/v/
    xSqNx7vJLDE&rel =1" type="applicati on/x-shockwave-flash"
    wmode="transpar ent" width="425" height="355"></embed></object>

    Thanks

  • Brian Muth

    #2
    Re: Regex in c#

    Regex r = new Regex ("src=\"(?<YouT ube>http://www\\.youtube\\ .com\\S*)\"");
    Match s = r.Match("<objec t width=\"425\" height=\"355\"> <param name=\"movie\"
    value=\"http://www.youtube.com/v/xSqNx7vJLDE&rel =1\"></param><param name=\"wmode\"v alue=\"transpar ent\"></param><embed
    src=\"http://www.youtube.com/v/xSqNx7vJLDE&rel =1\" type=\"applicat ion/x-shockwave-flash\"wmode=\" transparent\" width=\"425\"
    height=\"355\"> </embed></object>");

    Console.Write(s .Groups["YouTube"]);

    Watch out for unintended line-breaks.

    Brian

    Comment

    • Nightcrawler

      #3
      Re: Regex in c#

      On Nov 9, 1:54 pm, "Brian Muth" <bm...@mvps.org wrote:
      Regex r = new Regex ("src=\"(?<YouT ube>http://www\\.youtube\\ .com\\S*)\"");
      Match s = r.Match("<objec t width=\"425\" height=\"355\"> <param name=\"movie\"
      value=\"http://www.youtube.com/v/xSqNx7vJLDE&rel =1\"></param><param name=\"wmode\"v alue=\"transpar ent\"></param><embed
      src=\"http://www.youtube.com/v/xSqNx7vJLDE&rel =1\" type=\"applicat ion/x-shockwave-flash\"wmode=\" transparent\" width=\"425\"
      height=\"355\"> </embed></object>");
      >
      Console.Write(s .Groups["YouTube"]);
      >
      Watch out for unintended line-breaks.
      >
      Brian
      Brian,

      Thanks! How do I use this in a regularexpressi on validator in my aspx
      file. There is a problem using quotation marks within the
      ValidationExpre ssion="" property.

      Thanks

      Comment

      • Jesse Houwing

        #4
        Re: Regex in c#

        Hello Nightcrawler,
        On Nov 9, 1:54 pm, "Brian Muth" <bm...@mvps.org wrote:
        >
        >Regex r = new Regex
        >("src=\"(?<You Tube>http://www\\.youtube\\ .com\\S*)\"");
        >>
        >Match s = r.Match("<objec t width=\"425\" height=\"355\"> <param
        >name=\"movie \"
        >>
        >value=\"http ://www.youtube.com/v/xSqNx7vJLDE&rel =1\"></param><param
        >name=\"wmode\" value=\"transpa rent\"></param><embed
        >>
        >src=\"http://www.youtube.com/v/xSqNx7vJLDE&rel =1\"
        >type=\"applica tion/x-shockwave-flash\"wmode=\" transparent\"
        >width=\"425\ "
        >>
        >height=\"355\" ></embed></object>");
        >>
        >Console.Write( s.Groups["YouTube"]);
        >>
        >Watch out for unintended line-breaks.
        >>
        >Brian
        >>
        Brian,
        >
        Thanks! How do I use this in a regularexpressi on validator in my aspx
        file. There is a problem using quotation marks within the
        ValidationExpre ssion="" property.
        Write them as &quot; I guess... Or set the value through the designer.

        Jesse

        --
        Jesse Houwing
        jesse.houwing at sogeti.nl


        Comment

        Working...