How to write a regular expression that checks that the line contains either 2-3 capital letters of the Russian alphabet, or 3-4 capital letters of the Latin alphabet?

It works with me only with two separate regulars: [А-Я]{2,3} and [AZ]{3,4} .

  • 2
    Between them, put | if there are no other characters needed. Or provide more data on the line in the question. - Visman
  • 2-3 capital letters in a row? or may be in discord? - Grundy

1 answer 1

Using the pipe (symbol | ) will help in the selection.
Will find only the specified number of repetitions, more or less - already a failure.

 let log = document.querySelector('#log'), test = document.querySelector('#test'); test.addEventListener('input', e => { if(/^(?:[а-яё]{2,3}|[az]{4,6})$/i.test(test.value)){ log.style.color = 'green'; log.innerHTML = 'Passed!'; }else{ log.style.color = 'red'; log.innerHTML = 'Failed'; } }); 
 #test:focus{outline: none;} 
 <input type='text' id='test' autofocus /><br /> <span id='log'></span> 

  • You got lost here - VenZell
  • @VenZell, right, all the time I forget that for some reason ё not included in the set az. Discrimination! - user207618
  • Here is the symbol | just does not work for me. - Vladimir Smirnov
  • @ Vladimir Smirnov: How not to work? Smokes, or what? Show your code. - Wiktor Stribiżew
  • @ Vladimir Smirnov, how is "not working"? Everything works, share your code then. - user207618