.replace() في سلسلة. تعتبر مدخلات .replace() هي أولاً نمط regex الذي تريد البحث عنه. المعلمة الثانية هي السلسلة التي ستحل محل المطابقة أو الوظيفة لفعل شيء ما. let wrongText = "إن السماء فضية."؛يمكنك أيضًا الوصول إلى مجموعات الالتقاط في سلسلة الاستبدال باستخدام علامة الدولار (
let silverRegex = / silver /؛
wrongText.replace (silverRegex، "blue")؛
// Returns "السماء زرقاء."
$ ). "Code Code" .replace (/ (\ w +) \ s (\ w +) /، '$ 2 $ 1')؛
// إرجاع "رمز المعسكر"
"good" . ثم قم بتحديث متغير replaceText لاستبدال "good" بـ "okey-dokey" . .replace() للبحث .replace() .
testString: 'assert(code.match(/\.replace\(.*\)/), "You should use .replace() to search and replace.");'
- text: يجب أن يتغير تعبيرك المعتاد "This sandwich is good." إلى "This sandwich is okey-dokey."
testString: 'assert(result == "This sandwich is okey-dokey." && replaceText === "okey-dokey", "Your regex should change "This sandwich is good." to "This sandwich is okey-dokey."");'
- text: يجب عدم تغيير السطر الأخير.
testString: 'assert(code.match(/result\s*=\s*huhText\.replace\(.*?\)/), "You should not change the last line.");'
```