Files
freeCodeCamp/curriculum/challenges/russian/02-javascript-algorithms-and-data-structures/regular-expressions/match-whitespace.russian.md

2.7 KiB
Raw Blame History

id, title, challengeType, forumTopicId, localeTitle
id title challengeType forumTopicId localeTitle
587d7db8367417b2b2512ba3 Match Whitespace 1 301359 Совпадение пробелов

Description

На сегодняшний день проблемы охватывают соответствующие буквы алфавита и цифры. Вы также можете сопоставить пробелы или пробелы между буквами. Вы можете искать пробелы с помощью \s , которая является строчной s . Этот шаблон не только соответствует пробелу, но также возвращает карету, вкладку, форму и новые символы строки. Вы можете считать это похожим на класс символов [ \r\t\f\n\v] .
let whiteSpace = "Пробел. Пробел везде!"
пусть пространство Regex = / \ s / g;
whiteSpace.match (spaceRegex);
// Возвращает ["", ""]

Instructions

Измените регулярное выражение countWhiteSpace для поиска нескольких символов пробела в строке.

Tests

tests:
  - text: Your regex should use the global flag.
    testString: assert(countWhiteSpace.global);
  - text: Your regex should use the shorthand character <code>\s</code> to match all whitespace characters.
    testString: assert(/\\s/.test(countWhiteSpace.source));
  - text: Your regex should find eight spaces in <code>"Men are from Mars and women are from Venus."</code>
    testString: assert("Men are from Mars and women are from Venus.".match(countWhiteSpace).length == 8);
  - text: 'Your regex should find three spaces in <code>"Space: the final frontier."</code>'
    testString: 'assert("Space: the final frontier.".match(countWhiteSpace).length == 3);'
  - text: Your regex should find no spaces in <code>"MindYourPersonalSpace"</code>
    testString: assert("MindYourPersonalSpace".match(countWhiteSpace) == null);

Challenge Seed

let sample = "Whitespace is important in separating words";
let countWhiteSpace = /change/; // Change this line
let result = sample.match(countWhiteSpace);

Solution

let sample = "Whitespace is important in separating words";
let countWhiteSpace = /\s/g;
let result = sample.match(countWhiteSpace);