freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../regular-expressions/find-more-than-the-first-ma...

2.7 KiB

id title challengeType videoUrl localeTitle
587d7db4367417b2b2512b93 Find More Than the First Match 1 العثور على أكثر من المباراة الأولى

Description

حتى الآن ، كنت قادرًا على استخراج نمط أو البحث عنه مرة واحدة فقط.
let testStr = "Repeat، Repeat، Repeat"؛
دع ourRegex = / كرر /؛
testStr.match (ourRegex)؛
// Returns ["Repeat"]
للبحث أو استخراج نمط أكثر من مرة ، يمكنك استخدام علم g .
اترك repeatRegex = / Repeat / g؛
testStr.match (repeatRegex)؛
// Returns ["Repeat"، "Repeat"، "Repeat"]

Instructions

باستخدام regex starRegex ، ابحث starRegex الكلمات "Twinkle" من سلسلة twinkleStar . ملحوظة
يمكنك الحصول على العديد من العلامات على تعديلك مثل /search/gi

Tests

tests:
  - text: يجب أن يستخدم <code>starRegex</code> regex الخاص بك العلم العالمي <code>g</code>
    testString: 'assert(starRegex.flags.match(/g/).length == 1, "Your regex <code>starRegex</code> should use the global flag <code>g</code>");'
  - text: يجب أن يستخدم <code>starRegex</code> الخاص بك regex <code>starRegex</code> الحالة غير الحساسة <code>i</code>
    testString: 'assert(starRegex.flags.match(/i/).length == 1, "Your regex <code>starRegex</code> should use the case insensitive flag <code>i</code>");'
  - text: يجب أن تتطابق المطابقة مع كلمتين لكلمة <code>&quot;Twinkle&quot;</code>
    testString: 'assert(result.sort().join() == twinkleStar.match(/twinkle/gi).sort().join(), "Your match should match both occurrences of the word <code>"Twinkle"</code>");'
  - text: يجب أن تحتوي <code>result</code> المطابقة الخاصة بك على عنصرين.
    testString: 'assert(result.length == 2, "Your match <code>result</code> should have two elements in it.");'

Challenge Seed

let twinkleStar = "Twinkle, twinkle, little star";
let starRegex = /change/; // Change this line
let result = twinkleStar; // Change this line

Solution

// solution required