freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../regular-expressions/using-the-test-method.arabi...

2.3 KiB

id title challengeType videoUrl localeTitle
587d7db3367417b2b2512b8e Using the Test Method 1 باستخدام طريقة الاختبار

Description

يتم استخدام التعبيرات العادية في لغات البرمجة لمطابقة أجزاء من السلاسل. يمكنك إنشاء أنماط لمساعدتك في إجراء ذلك المطابقة. إذا كنت تريد العثور على الكلمة "the" في السلسلة "The dog chased the cat" ، يمكنك استخدام التعبير العادي التالي: /the/ . لاحظ أن علامات الاقتباس ليست مطلوبة في التعبير العادي. جافا سكريبت لديها طرق متعددة لاستخدام regexes. طريقة واحدة لاختبار regex تستخدم طريقة .test() . و .test() يأخذ طريقة التعبير المعتاد، وينطبق ذلك إلى سلسلة (التي يتم وضعها داخل قوسين)، وإرجاع true أو false إذا وجد النمط الخاص بك شيئا أم لا.
السماح testStr = "freeCodeCamp" ؛
let testRegex = / Code /؛
testRegex.test (testStr)؛
// يعود صحيح

Instructions

قم myRegex regex على السلسلة myString باستخدام طريقة .test() .

Tests

tests:
  - text: يجب عليك استخدام <code>.test()</code> لاختبار regex.
    testString: 'assert(code.match(/myRegex.test\(\s*myString\s*\)/), "You should use <code>.test()</code> to test the regex.");'
  - text: نتيجة الخاص بك يجب أن تعود <code>true</code> .
    testString: 'assert(result === true, "Your result should return <code>true</code>.");'

Challenge Seed

let myString = "Hello, World!";
let myRegex = /Hello/;
let result = myRegex; // Change this line

Solution

// solution required