Verification: a143cc29221c9be0

Php check url and redirect

Содержание

C++

#include

#include

using namespace std;

bool isValidURL(string url)

{

  const regex pattern("((http|https)://)(www.)?[a-zA-Z0-9@:%._\\+~#?&//=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%._\\+~#?&//=]*)");

  if (url.empty())

  {

     return false;

  }

  if(regex_match(url, pattern))

  {

    return true;

  }

  else

  {

    return false;

  }

}

int main()

{

  if (isValidURL(url))

  {

    cout "YES";

  }

  else

  {

    cout "NO";

  }

  return 0;

}

Java

import java.util.regex.*;

class GFG {

    public static boolean

    isValidURL(String url)

    {

        String regex = "((http|https)://)(www.)?"

              + "[a-zA-Z0-9@:%._\\+~#?&//=]"

              + "{2,256}\\.[a-z]"

              + "{2,6}\\b([-a-zA-Z0-9@:%"

              + "._\\+~#?&//=]*)";

        Pattern p = Pattern.compile(regex);

        if (url == null) {

            return false;

        }

        Matcher m = p.matcher(url);

        return m.matches();

    }

    public static void main(String args[])

    {

        String url

        if (isValidURL(url) == true) {

            System.out.println("Yes");

        }

        else

            System.out.println("NO");

    }

}