Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Embedly api regex in c#
    primarykey
    data
    text
    <p>Embedly has a great regex generator with which you can use to verfiy the correctnes of services urls(<a href="http://api.embed.ly/tools/generator" rel="nofollow noreferrer">http://api.embed.ly/tools/generator</a>). It generates javascript regexes, but unfortunately it does not generate c# regex expressions. As far as I know though, c# uses the same ECMA regex definition, and I should therefore be able to use the in C#</p> <p>So what I would like to achieve is take the generated regex from the embdly site and just paste it into my c# code.</p> <p>The javascript regex would look like this: </p> <pre><code>/http:\/\/(.*youtube\.com\/watch.*|.*\.youtube\.com\/v\/.*|youtu\.be\/.*|.*\.youtube\.com\/user\/.*#.*|.*\.youtube\.com\/.*#.*\/.*|picasaweb\.google\.com.*\/.*\/.*#.*|picasaweb\.google\.com.*\/lh\/photo\/.*|picasaweb\.google\.com.*\/.*\/.*)/i </code></pre> <p>and should match urls like:</p> <p><a href="http://picasaweb.google.com/westerek/LadakhDolinaMarkha?feat=featured#5497194022344000402" rel="nofollow noreferrer">http://picasaweb.google.com/westerek/LadakhDolinaMarkha?feat=featured#5497194022344000402</a> <a href="http://www.youtube.com/watch?v=GVDc1uXda6Y&amp;feature=related" rel="nofollow noreferrer">http://www.youtube.com/watch?v=GVDc1uXda6Y&amp;feature=related</a></p> <p>What I have so far is the following:</p> <pre><code>Regex regex = new Regex( "[/http:\\/\\/(.*youtube\\.com\\/watch.*|.*\\.youtube\\.com\\/"+ "v\\/.*|youtu\\.be\\/.*|.*\\.youtube\\.com\\/user\\/.*#.*|.*\\."+ "youtube\\.com\\/.*#.*\\/.*|picasaweb\\.google\\.com.*\\/.*\\/"+ ".*#.*|picasaweb\\.google\\.com.*\\/lh\\/photo\\/.*|picasaweb"+ "\\.google\\.com.*\\/.*\\/.*)/i]", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled ); </code></pre> <p>.. but this only gives me partial matches.. </p> <p>EDIT: Solution: Just paste the embedly javascript regex expression into strEmbdlyRegex string in the following snippet.</p> <pre><code> string strEmbdlyRegex = @"/http:\/\/(.*youtube\.com\/watch.*|.*\.youtube\.com\/v\/.*|youtu\.be\/.*|.*\.youtube\.com\/user\/.*#.*|.*\.youtube\.com\/.*#.*\/.*)/i"; string strRegx = strEmbdlyRegex.Remove(0, 1); strRegx = strRegx.Remove(strRegx.IndexOf("("), 1); strRegx = strRegx.Remove(strRegx.LastIndexOf(")/i"), 3); strRegx = strRegx + "]"; regex = new Regex( strRegx, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.ECMAScript | RegexOptions.Compiled ); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload