freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../regular-expressions/match-a-literal-string-with...

4.3 KiB

id title challengeType videoUrl localeTitle
587d7db4367417b2b2512b90 Match a Literal String with Different Possibilities 1 تطابق سلسلة حرفية مع الاحتمالات المختلفة

Description

باستخدام regexes مثل /coding/ ، يمكنك البحث عن نمط "coding" في سلسلة أخرى. يعد هذا أمرًا قويًا للبحث عن سلاسل مفردة ، ولكنه يقتصر على نمط واحد فقط. يمكنك البحث عن أنماط متعددة باستخدام alternation أو OR المشغل: | . هذا المشغل يطابق الأنماط قبل أو بعدها. على سبيل المثال ، إذا كنت تريد مطابقة "yes" أو "no" ، فإن التعبير المعتاد الذي تريده هو /yes|no/ . يمكنك أيضًا البحث عن أكثر من نمطين فقط. يمكنك القيام بذلك عن طريق إضافة المزيد من الأنماط مع المزيد من عوامل تشغيل OR تفصل بينها ، مثل /yes|no|maybe/ .

Instructions

أكمل petRegex regex petRegex مع الحيوانات الأليفة "dog" أو "cat" أو "bird" أو "fish" .

Tests

tests:
  - text: يجب إرجاع <code>petRegex</code> الخاص بك regex <code>true</code> للسلسلة <code>&quot;John has a pet dog.&quot;</code>
    testString: 'assert(petRegex.test("John has a pet dog."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"John has a pet dog."</code>");'
  - text: يجب إرجاع <code>petRegex</code> الخاص بك regex <code>false</code> لسلسلة <code>&quot;Emma has a pet rock.&quot;</code>
    testString: 'assert(!petRegex.test("Emma has a pet rock."), "Your regex <code>petRegex</code> should return <code>false</code> for the string <code>"Emma has a pet rock."</code>");'
  - text: يجب إرجاع <code>petRegex</code> الخاص بك regex <code>true</code> للسلسلة <code>&quot;Emma has a pet bird.&quot;</code>
    testString: 'assert(petRegex.test("Emma has a pet bird."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"Emma has a pet bird."</code>");'
  - text: يجب إعادة <code>petRegex</code> الخاص بك regex <code>true</code> للسلسلة <code>&quot;Liz has a pet cat.&quot;</code>
    testString: 'assert(petRegex.test("Liz has a pet cat."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"Liz has a pet cat."</code>");'
  - text: يجب إعادة <code>petRegex</code> الخاص بك regex <code>false</code> للسلسلة <code>&quot;Kara has a pet dolphin.&quot;</code> <code>petRegex</code> <code>&quot;Kara has a pet dolphin.&quot;</code>
    testString: 'assert(!petRegex.test("Kara has a pet dolphin."), "Your regex <code>petRegex</code> should return <code>false</code> for the string <code>"Kara has a pet dolphin."</code>");'
  - text: يجب أن يعود <code>petRegex</code> المعتاد الخاص بك <code>true</code> للسلسلة <code>&quot;Alice has a pet fish.&quot;</code>
    testString: 'assert(petRegex.test("Alice has a pet fish."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"Alice has a pet fish."</code>");'
  - text: يجب أن <code>petRegex</code> المعتاد الخاص بك <code>false</code> للسلسلة <code>&quot;Jimmy has a pet computer.&quot;</code>
    testString: 'assert(!petRegex.test("Jimmy has a pet computer."), "Your regex <code>petRegex</code> should return <code>false</code> for the string <code>"Jimmy has a pet computer."</code>");'

Challenge Seed

let petString = "James has a pet cat.";
let petRegex = /change/; // Change this line
let result = petRegex.test(petString);

Solution

// solution required