Files
freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end.md
freeCodeCamp's Camper Bot e6b05ee25d chore(i18n,learn): processed translations (#54537)
Co-authored-by: Naomi <nhcarrigan@gmail.com>
2024-04-26 12:26:37 +07:00

1.7 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7dbb367417b2b2512bac إزالة Whitespace من البداية و النهاية (Remove Whitespace from Start and End) 1 301362 remove-whitespace-from-start-and-end

--description--

في بعض الأحيان لا تكون الـ whitespaces حول الـ strings مطلوبة ولكنها موجودة. المعالجة النموذجية للـ strings هي إزالة الـ whitespace في بدايتها ونهايتها.

--instructions--

اكتب regex و استخدم الطرق المناسبة لإزالة الـ whitespace في بداية و نهاية الـ strings.

ملاحظة: طريقة String.prototype.trim() ستعمل هنا، ولكن ستحتاج إلى إكمال هذا التحدي باستخدام regular expressions.

--hints--

result يجب أن تكون مساوية للـ string الآتي Hello, World!

assert(result === 'Hello, World!');

يجب ألا يستخدم حلك طريقة String.prototype.trim().

assert(!__helpers.removeJSComments(code).match(/\.?[\s\S]*?trim/));

متغير النتيجة result يجب ألا يتم تعيينه مباشرة إلى string

assert(!__helpers.removeJSComments(code).match(/result\s*=\s*["'`].*?["'`]/));

لا ينبغي تغيير قيمة متغير hello.

assert(hello === '   Hello, World!  ');

--seed--

--seed-contents--

let hello = "   Hello, World!  ";
let wsRegex = /change/; // Change this line
let result = hello; // Change this line

--solutions--

let hello = "   Hello, World!  ";
let wsRegex = /^(\s+)(.+[^\s])(\s+)$/;
let result = hello.replace(wsRegex, '$2');