Oliver Eyton-Williams bd68b70f3d
Feat: hide blocks not challenges (#39504)
* fix: remove isHidden flag from frontmatter

* fix: add isUpcomingChange

Co-authored-by: Ahmad Abdolsaheb <ahmad.abdolsaheb@gmail.com>

* feat: hide blocks not challenges

Co-authored-by: Ahmad Abdolsaheb <ahmad.abdolsaheb@gmail.com>

Co-authored-by: Ahmad Abdolsaheb <ahmad.abdolsaheb@gmail.com>
2020-09-03 15:07:40 -07:00

1.8 KiB

id, title, challengeType, forumTopicId
id title challengeType forumTopicId
587d7db4367417b2b2512b92 Extract Matches 1 301340

Description

So far, you have only been checking if a pattern exists or not within a string. You can also extract the actual matches you found with the .match() method. To use the .match() method, apply the method on a string and pass in the regex inside the parentheses. Here's an example:
"Hello, World!".match(/Hello/);
// Returns ["Hello"]
let ourStr = "Regular expressions";
let ourRegex = /expressions/;
ourStr.match(ourRegex);
// Returns ["expressions"]

Note that the .match syntax is the "opposite" of the .test method you have been using thus far:

'string'.match(/regex/);
/regex/.test('string');

Instructions

Apply the .match() method to extract the word coding.

Tests

tests:
  - text: The <code>result</code> should have the word <code>coding</code>
    testString: assert(result.join() === "coding");
  - text: Your regex <code>codingRegex</code> should search for <code>coding</code>
    testString: assert(codingRegex.source === "coding");
  - text: You should use the <code>.match()</code> method.
    testString: assert(code.match(/\.match\(.*\)/));

Challenge Seed

let extractStr = "Extract the word 'coding' from this string.";
let codingRegex = /change/; // Change this line
let result = extractStr; // Change this line

Solution

let extractStr = "Extract the word 'coding' from this string.";
let codingRegex = /coding/; // Change this line
let result = extractStr.match(codingRegex); // Change this line