Check if string is a valid URL Your task is to write a program or function that checks if a string is a valid URL.

Given a string as input, you will output a truthy value if the input is a valid URL. If it is not, output a falsey value. An input string is considered a valid URL if all of the following criteria are met:


Begins with http:// or https://
At least one and up to 128 labels (parts of URL delimited by a period)


Labels delimited by a period
Contain only letters, digits, and hyphens
Do not start nor end with a hyphen
Third and fourth characters cannot be a hyphen, unless the first two characters are 'xn'
A label may contain zero to 63 characters

The length of the string does not exceed 253 characters


This is a code-golf, with standard rules.



https://en.wikipedia.org/wiki/Domain_Name_System#Domain_name_syntax
JavaScript, 114 bytes

x=&gt;RegExp(`^(?!.*([./](-|(?!xn)[^/]{2}--)|-[./]|-$))https?://${a='[a-zA-Z0-9-]{0,63}'}(?:\\.${a}){0,127}`).test(x)


Hopes it works.

For real URLs, you should use:

x=&gt;eval(`try{new URL(x)}catch(e){}`)


Thanks to ThePirateBay, construct regex from string save 3 bytes.