Files
freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/regular-expressions/match-ending-string-patterns.md
2023-01-11 13:20:09 +05:30

1.8 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7db7367417b2b2512b9e Match Ending String Patterns 1 301352 match-ending-string-patterns

--description--

في التحدي الأخير، تعلمت استخدام رمز الـ caret للبحث عن أنماط في بداية ال strings. وهناك أيضا طريقة للبحث عن أنماط في نهاية ال strings.

يمكنك البحث في نهاية ال strings باستخدام رمز إشارة الدولار $ في نهاية الـ regex.

let theEnding = "This is a never ending story";
let storyRegex = /story$/;
storyRegex.test(theEnding);
let noEnding = "Sometimes a story will have to end";
storyRegex.test(noEnding);

أول استدعاء لـ test سيعيد true والثاني سيعيد false.

--instructions--

استخدم رمز الدولار ($) لمطابقة المقطع النصي caboose في نهاية caboose.

--hints--

يجب عليك البحث عن caboose باستخدام علامة الدولار $ في نمط regex.

assert(lastRegex.source == 'caboose$');

لا يجب أن يستخدم الـ regex الخاص بك أي flags.

assert(lastRegex.flags == '');

يجب عليك مطابقة caboose في نهاية السلسلة The last car on a train is the caboose

lastRegex.lastIndex = 0;
assert(lastRegex.test('The last car on a train is the caboose'));

--seed--

--seed-contents--

let caboose = "The last car on a train is the caboose";
let lastRegex = /change/; // Change this line
let result = lastRegex.test(caboose);

--solutions--

let caboose = "The last car on a train is the caboose";
let lastRegex = /caboose$/; // Change this line
let result = lastRegex.test(caboose);