fix: allow g flag on regex (#37941)
This commit is contained in:
committed by
Christopher McCormack
parent
0adfc79c7a
commit
1b06bb29f0
@ -13,7 +13,7 @@ Then check whether the desired string groups are in the test string by using the
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
let testStr = "Pumpkin";
|
let testStr = "Pumpkin";
|
||||||
let testRegex = /P(engu|umpk)in/g;
|
let testRegex = /P(engu|umpk)in/;
|
||||||
testRegex.test(testStr);
|
testRegex.test(testStr);
|
||||||
// Returns true
|
// Returns true
|
||||||
```
|
```
|
||||||
@ -32,11 +32,11 @@ Then fix the code so that the regex that you have created is checked against <co
|
|||||||
```yml
|
```yml
|
||||||
tests:
|
tests:
|
||||||
- text: Your regex <code>myRegex</code> should return <code>true</code> for the string <code>Franklin D. Roosevelt</code>
|
- text: Your regex <code>myRegex</code> should return <code>true</code> for the string <code>Franklin D. Roosevelt</code>
|
||||||
testString: assert(myRegex.test('Franklin D. Roosevelt'));
|
testString: myRegex.lastIndex = 0; assert(myRegex.test('Franklin D. Roosevelt'));
|
||||||
- text: Your regex <code>myRegex</code> should return <code>true</code> for the string <code>Eleanor Roosevelt</code>
|
- text: Your regex <code>myRegex</code> should return <code>true</code> for the string <code>Eleanor Roosevelt</code>
|
||||||
testString: assert(myRegex.test('Eleanor Roosevelt'));
|
testString: myRegex.lastIndex = 0; assert(myRegex.test('Eleanor Roosevelt'));
|
||||||
- text: Your regex <code>myRegex</code> should return <code>false</code> for the string <code>Franklin Rosevelt</code>
|
- text: Your regex <code>myRegex</code> should return <code>false</code> for the string <code>Franklin Rosevelt</code>
|
||||||
testString: assert(!myRegex.test('Franklin Rosevelt'));
|
testString: myRegex.lastIndex = 0; assert(!myRegex.test('Franklin Rosevelt'));
|
||||||
- text: You should use <code>.test()</code> to test the regex.
|
- text: You should use <code>.test()</code> to test the regex.
|
||||||
testString: assert(code.match(/myRegex.test\(\s*myString\s*\)/));
|
testString: assert(code.match(/myRegex.test\(\s*myString\s*\)/));
|
||||||
- text: Your result should return <code>true</code>.
|
- text: Your result should return <code>true</code>.
|
||||||
|
Reference in New Issue
Block a user