mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-02-21 11:04:47 -05:00
1.9 KiB
1.9 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| 587d7db4367417b2b2512b92 | استخراج المطابقات (Extract Matches) | 1 | 301340 | extract-matches |
--description--
حتى الآن، كنت تتحقق فقط من وجود أو عدم وجود نمط داخل string. يمكنك أيضا استخراج المطابقات الفعلية التي وجدتها باستخدام دالة .match().
لاستخدام وظيفة .match() ، قم بتطبيق الوظيفة على string ومرر بداخلها الـ regex في الأقواس.
إليك مثال:
"Hello, World!".match(/Hello/);
let ourStr = "Regular expressions";
let ourRegex = /expressions/;
ourStr.match(ourRegex);
ستعيد أول match القيمة ["Hello"] والثانية ستعيد ["expressions"].
لاحظ أن الـ syntax لـ.match هو "عكس" لدالة .test التي تستخدمها حتى الآن:
'string'.match(/regex/);
/regex/.test('string');
--instructions--
قم بتطبيق دالة .match() لاستخراج الـ string الآتي coding.
--hints--
result يجب أن تحتوي على coding
assert(result.join() === 'coding');
الـ regex الخاص بك codingRegex يجب أن يبحث عن الـ string الآتي coding
assert(codingRegex.source === 'coding');
يجب أن يستخدم الكود الخاص بك دالة .match().
assert(code.match(/\.match\(.*\)/));
--seed--
--seed-contents--
let extractStr = "Extract the word 'coding' from this string.";
let codingRegex = /change/; // Change this line
let result = extractStr; // Change this line
--solutions--
let extractStr = "Extract the word 'coding' from this string.";
let codingRegex = /coding/; // Change this line
let result = extractStr.match(codingRegex); // Change this line