Files

31 lines
778 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Use Capture Groups to Search and Replace
---
# Use Capture Groups to Search and Replace
2018-10-12 15:37:13 -04:00
---
## Problem Explanation
2018-10-12 15:37:13 -04:00
Using `.replace()` with the first parameter set to find the part of the original string to replace, and the second parameter should be the replacement.
---
## Hints
### Hint 1
2018-10-12 15:37:13 -04:00
Modify the regex so that `fixRegex` detects the part of the string to replace and the variable `replaceText` should be modified to the string that will replace `fixRegex`.
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
2018-10-12 15:37:13 -04:00
```javascript
let huhText = "This sandwich is good.";
let fixRegex = /good/; // Change this line
let replaceText = "okey-dokey"; // Change this line
let result = huhText.replace(fixRegex, replaceText);
```
</details>