freeCodeCamp/curriculum/challenges/russian/02-javascript-algorithms-an.../regular-expressions/specify-upper-and-lower-num...

3.2 KiB
Raw Blame History

id title challengeType forumTopicId localeTitle
587d7db9367417b2b2512ba5 Specify Upper and Lower Number of Matches 1 301367 Указать верхнее и нижнее число совпадений

Description

Напомним, что вы используете знак плюс + для поиска одного или нескольких символов и звездочки * для поиска нулевого или большего количества символов. Это удобно, но иногда вы хотите соответствовать определенному диапазону шаблонов. Вы можете указать нижнее и верхнее число шаблонов с quantity specifiers . Спецификаторы количества используются с фигурными скобками ( { и } ). Вы устанавливаете два числа между фигурными скобками - для нижнего и верхнего числа шаблонов. Например, чтобы соответствовать только букве a появляющейся между 3 и 5 раз в строке "ah" , ваше регулярное выражение будет /a{3,5}h/ .
пусть A4 = «aaaah»;
пусть A2 = "aah";
пусть несколько А = / а {3,5} ч /;
multipleA.test (А4); // Возвращает true
multipleA.test (А2); // Возвращает false

Instructions

Измените regex ohRegex на соответствие только 3 - 6 буквам h в слове "Oh no" .

Tests

tests:
  - text: Your regex should use curly brackets.
    testString: assert(ohRegex.source.match(/{.*?}/).length > 0);
  - text: Your regex should not match <code>"Ohh no"</code>
    testString: assert(!ohRegex.test("Ohh no"));
  - text: Your regex should match <code>"Ohhh no"</code>
    testString: assert("Ohhh no".match(ohRegex)[0].length === 7);
  - text: Your regex should match <code>"Ohhhh no"</code>
    testString: assert("Ohhhh no".match(ohRegex)[0].length === 8);
  - text: Your regex should match <code>"Ohhhhh no"</code>
    testString: assert("Ohhhhh no".match(ohRegex)[0].length === 9);
  - text: Your regex should match <code>"Ohhhhhh no"</code>
    testString: assert("Ohhhhhh no".match(ohRegex)[0].length === 10);
  - text: Your regex should not match <code>"Ohhhhhhh no"</code>
    testString: assert(!ohRegex.test("Ohhhhhhh no"));

Challenge Seed

let ohStr = "Ohhh no";
let ohRegex = /change/; // Change this line
let result = ohRegex.test(ohStr);

Solution

let ohStr = "Ohhh no";
let ohRegex = /Oh{3,6} no/; // Change this line
let result = ohRegex.test(ohStr);