2.9 KiB
2.9 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7dbb367417b2b2512bab | Use Capture Groups to Search and Replace | 1 | استخدم مجموعات الالتقاط للبحث واستبدال |
Description
.replace()
في سلسلة. تعتبر مدخلات .replace()
هي أولاً نمط regex الذي تريد البحث عنه. المعلمة الثانية هي السلسلة التي ستحل محل المطابقة أو الوظيفة لفعل شيء ما. let wrongText = "إن السماء فضية."؛يمكنك أيضًا الوصول إلى مجموعات الالتقاط في سلسلة الاستبدال باستخدام علامة الدولار (
let silverRegex = / silver /؛
wrongText.replace (silverRegex، "blue")؛
// Returns "السماء زرقاء."
$
). "Code Code" .replace (/ (\ w +) \ s (\ w +) /، '$ 2 $ 1')؛
// إرجاع "رمز المعسكر"
Instructions
"good"
. ثم قم بتحديث متغير replaceText
لاستبدال "good"
بـ "okey-dokey"
. Tests
tests:
- text: يجب عليك استخدام <code>.replace()</code> للبحث <code>.replace()</code> .
testString: 'assert(code.match(/\.replace\(.*\)/), "You should use <code>.replace()</code> to search and replace.");'
- text: يجب أن يتغير تعبيرك المعتاد <code>"This sandwich is good."</code> إلى <code>"This sandwich is okey-dokey."</code>
testString: 'assert(result == "This sandwich is okey-dokey." && replaceText === "okey-dokey", "Your regex should change <code>"This sandwich is good."</code> to <code>"This sandwich is okey-dokey."</code>");'
- text: يجب عدم تغيير السطر الأخير.
testString: 'assert(code.match(/result\s*=\s*huhText\.replace\(.*?\)/), "You should not change the last line.");'
Challenge Seed
let huhText = "This sandwich is good.";
let fixRegex = /change/; // Change this line
let replaceText = ""; // Change this line
let result = huhText.replace(fixRegex, replaceText);
Solution
// solution required