freeCodeCamp/curriculum/challenges/russian/02-javascript-algorithms-an.../regular-expressions/extract-matches.russian.md

2.0 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d7db4367417b2b2512b92 Extract Matches 1 Экстракционные матчи

Description

До сих пор вы проверяли, существует ли шаблон в строке или нет. Вы также можете извлечь фактические совпадения, найденные с помощью .match() . Чтобы использовать метод .match() , примените метод к строке и передайте в регулярное выражение внутри круглых скобок. Вот пример:
«Hello, World!». Match (/ Hello /);
// Возвращает ["Hello"]
let ourStr = "Регулярные выражения";
пусть нашRegex = / выражения /;
ourStr.match (ourRegex);
// Возвращает ["выражения"]

Instructions

Нанести .match() метод , чтобы извлечь слово coding .

Tests

tests:
  - text: <code>result</code> должен иметь слово <code>coding</code>
    testString: 'assert(result.join() === "coding", "The <code>result</code> should have the word <code>coding</code>");'
  - text: ''
    testString: 'assert(codingRegex.source === "coding", "Your regex <code>codingRegex</code> should search for <code>coding</code>");'
  - text: ''
    testString: 'assert(code.match(/\.match\(.*\)/), "You should use the <code>.match()</code> method.");'

Challenge Seed

let extractStr = "Extract the word 'coding' from this string.";
let codingRegex = /change/; // Change this line
let result = extractStr; // Change this line

Solution

// solution required