O
O
Oleg2017-06-21 12:10:21
JavaScript
Oleg, 2017-06-21 12:10:21

RegEx for Cyrillic domains?

/(http(s)?:\/\/.)?(www\.)?[-a-z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-z0-9@:%_\+.~#?&//=]*)/ig

How to make a selection of domains with Cyrillic along with Latin?
I also tried to replace az with a-z, no result ..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Pushkarev, 2017-06-21
@AXP-dev

www.prntscr.com/fmc99r
www.prntscr.com/fmcajx

@([\p{Cyrillic}\p{Latin}\d\.-]{1,64})?\.(?:\x{0440}\x{0444}|ru|su|arpa|info|aero|name|[a-z]{3})@/igu

N
Nikolai Vasiliev, 2017-06-21
@Nickolay_V

I use Nod's url module for verification. It parses the address (always with the protocol) and decomposes it into components - protocol, name, port, path, parameters, etc., and immediately converts the name into a panic code - there is no need to invent anything with national characters in the regexp.

function validateUrl(address) {
  let url = require('url');
  let addressRegexp = new RegExp('^([\\w\\-]+?\\.?)+?\\.[\\w\\-]+?$');

  if (address.search(/^(ftp|http|https):\/\//) === -1) { address = 'http://' + address; }	

  let hname = url.parse(address).hostname;

  if (hname.length < 4 || hname.length > 255 || !addressRegexp.test(hname)) {
    throw new WrongInput('');
  }
}

https://nodejs.org/dist/latest-v6.x/docs/api/url.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question