A
A
Alexander Makarov2018-05-09 19:45:37
JavaScript
Alexander Makarov, 2018-05-09 19:45:37

What am I doing wrong in the routine?

Tell me, good people, what am I doing wrong?

/^https:\/\/([\w]+\.)?avito.ru\/[\w-]+\/.+(?!(_[\d]{4,}))$/.test(x)

I need to check that the avito link does not contain _ at the end and a number consisting of 4 or more digits
. That is, when checking
https://www.avito.ru/moskva/odezhda_obuv_aksessuary/magazin_pizham_kigurumi_na_lubyanke_56545
should return false
and when checked https://www.avito.ru/moskva/kvartiry/snimu-true

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2018-05-09
@AlexReal

Maybe you don't need to check the whole line? If all links are correct, then check only the end of the line - you can reverse the line .split('').reverse().join('')and check only the beginning /^\d{4,}_/
Here is one regular expression for your requirement:

var re = new RegExp('^https?://(\\w+\\.)?avito\\.ru/([^/]+/)+([a-z_]+(?!_\\d{4,}))$');

var t1 = 'https://www.avito.ru/moskva/odezhda_obuv_aksessuary/magazin_pizham_kigurumi_na_lubyanke_56545';
var t2 = 'https://www.avito.ru/moskva/kvartiry/snimu';

re.test(t1) // false
re.test(t2) // true

S
Sergey, 2018-05-09
@Sergamers

Try to do the opposite.
^https:\/{2}(?:.*?\.)?avito\.ru[\/\w-]+(_\d{4,})$

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question