Files
2023-01-06 00:37:55 +09:00

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