4.3 KiB
4.3 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db4367417b2b2512b90 | Match a Literal String with Different Possibilities | 1 | تطابق سلسلة حرفية مع الاحتمالات المختلفة |
Description
/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>"John has a pet dog."</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>"Emma has a pet rock."</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>"Emma has a pet bird."</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>"Liz has a pet cat."</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>"Kara has a pet dolphin."</code> <code>petRegex</code> <code>"Kara has a pet dolphin."</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>"Alice has a pet fish."</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>"Jimmy has a pet computer."</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