Question: How to check if the string contains a valid vimeo url using javascript ?

Example : <https://vimeo.com/23374724> is a valid url.

Answer: 
**Don't** rely on **Regex** as Vimeo tends to change/update their URL pattern every now and then. As of *October 2nd, 2017*, there are in total of six URL schemes Vimeo supports.

```
https://vimeo.com/*
https://vimeo.com/*/*/video/*
https://vimeo.com/album/*/video/*
https://vimeo.com/channels/*/*
https://vimeo.com/groups/*/videos/*
https://vimeo.com/ondemand/*/*

```

Instead, use their API to validate vimeo URLs. Here is this oEmbed ([doc](https://developer.vimeo.com/apis/oembed)) API which takes an URL, checks its validity and return a object with bunch of video information(check out the dev page). Although not intended but we can easily use this to validate whether a given URL is from Vimeo or not.

So, with ajax it would look like this,

```
var VIMEO_BASE_URL = "https://vimeo.com/api/oembed.json?url=";
var yourTestUrl = "https://vimeo.com/23374724";

$.ajax({
  url: VIMEO_BASE_URL + yourTestUrl,
  type: 'GET',
  success: function(data) {
    if (data != null && data.video_id > 0)
      // Valid Vimeo url
    else
      // not a valid Vimeo url
  },
  error: function(data) {
    // not a valid Vimeo url
  }
});

```
You can use the following regex:

```
(?:https?\:\/\/)?(?:www\.)?(?:vimeo\.com\/)([0-9]+)

```

The id of the video will be captured in group 1, if you need to use that. You can see it in action on [debuggex](http://www.debuggex.com/?re=%28?%3ahttps?%5C%3a%5C/%5C/%29?%28?%3awww%5C.%29?%28?%3avimeo%5C.com%5C/%29%28%5B0-9%5D%2b%29&flags=&str=https://vimeo.com/23374724%20and%20https://vimeo.com/23374726).