2.3 KiB
2.3 KiB
id, title, challengeType, videoUrl, localeTitle
| 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