fix(curriculum): change some example codes to non-interactive (#66161)

This commit is contained in:
Aditya Singh
2026-03-05 16:08:05 +05:30
committed by GitHub
parent da10086379
commit 3ab093b7b3
2 changed files with 33 additions and 19 deletions
@@ -29,16 +29,12 @@ console.log(test); // false
- **`match()` Method**: This method accepts a regular expression, although you can also pass a string which will be constructed into a regular expression. The `match` method returns the match array for the string.
:::interactive_editor
```js
const regex = /freeCodeCamp/;
const match = "freeCodeCamp".match(regex);
console.log(match); // ["freeCodeCamp"]
console.log(match); // ['freeCodeCamp', index: 0, input: 'freeCodeCamp', groups: undefined]
```
:::
- **`replace()` Method**: This method accepts two arguments: the regular expression to match (or a string), and the string to replace the match with (or a function to run against each match).
:::interactive_editor
@@ -140,15 +136,26 @@ console.log(end.test(str)); // true
- **`d` Flag**: This flag expands the information you get in a match object.
:::interactive_editor
```js
const regex = /freecodecamp/di;
const string = "we love freecodecamp isn't freecodecamp great?";
console.log(string.match(regex));
```
:::
And the result is:
```js
// [
// 'freecodecamp',
// index: 8,
// input: "we love freecodecamp isn't freecodecamp great?",
// groups: undefined,
// indices: [
// 0: [8, 20],
// groups: undefined
// ]
// ]
```
- **`u` Flag**: This expands the functionality of a regular expression to allow it to match special unicode characters. The `u` flag gives you access to special classes like the `Extended_Pictographic` to match most emoji. There is also a `v` flag, which further expands the functionality of the unicode matching.
- **`y` Flag**: The sticky modifier behaves very similarly to the global modifier, but with a few exceptions. The biggest one is that a global regular expression will start from lastIndex and search the entire remainder of the string for another match, but a sticky regular expression will return null and reset the lastIndex to 0 if there is not immediately a match at the previous lastIndex.
@@ -260,8 +267,8 @@ console.log("freecoooooooodecamp".replace(regex, "paid$1world"));
```js
const regex = /(hello) \1/i;
console.log(regex.test("hello hello")); // true
console.log(regex.test("hello world")); // false
console.log(regex.test("hello hello")); // true
console.log(regex.test("hello world")); // false
```
:::
@@ -2698,16 +2698,12 @@ console.log(test); // false
- **`match()` Method**: This method accepts a regular expression, although you can also pass a string which will be constructed into a regular expression. The `match` method returns the match array for the string.
:::interactive_editor
```js
const regex = /freeCodeCamp/;
const match = "freeCodeCamp".match(regex);
console.log(match); // ["freeCodeCamp"]
console.log(match); // ['freeCodeCamp', index: 0, input: 'freeCodeCamp', groups: undefined]
```
:::
- **`replace()` Method**: This method accepts two arguments: the regular expression to match (or a string), and the string to replace the match with (or a function to run against each match).
:::interactive_editor
@@ -2809,15 +2805,26 @@ console.log(end.test(str)); // true
- **`d` Flag**: This flag expands the information you get in a match object.
:::interactive_editor
```ts
```js
const regex = /freecodecamp/di;
const string = "we love freecodecamp isn't freecodecamp great?";
console.log(string.match(regex));
```
:::
And the result is:
```js
// [
// 'freecodecamp',
// index: 8,
// input: "we love freecodecamp isn't freecodecamp great?",
// groups: undefined,
// indices: [
// 0: [8, 20],
// groups: undefined
// ]
// ]
```
- **`u` Flag**: This expands the functionality of a regular expression to allow it to match special unicode characters. The `u` flag gives you access to special classes like the `Extended_Pictographic` to match most emoji. There is also a `v` flag, which further expands the functionality of the unicode matching.
- **`y` Flag**: The sticky modifier behaves very similarly to the global modifier, but with a few exceptions. The biggest one is that a global regular expression will start from lastIndex and search the entire remainder of the string for another match, but a sticky regular expression will return null and reset the lastIndex to 0 if there is not immediately a match at the previous lastIndex.