Skip to content

#288 Two Regular Expression Methods

Adam Kubiś edited this page Oct 28, 2026 · 1 revision

288 Two Regular Expression Methods

There are three methods (we exclude compile) that you can use with regular expression literals.

Use these two methods to fix the code.

One method returns a boolean if there is a match.

The other method returns an iterator from a search.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/288 Two Regular Expression Methods.js"

Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.

Current implementation and tests

This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.

//There are three methods (we exclude compile) that you can use with regular expression literals.
//Use these two methods to fix the code.
//One method returns a boolean if there is a match.
//The other method returns an iterator from a search.
function twoMethods() {
	// find and equals are not regular expression methods.  Replace them.
	//	let methodOne = /hello/.find("hello")[0] === "hello"
	// 	let methodTwo = /hello/.equals("hello") // returns a boolean
	const methodOne = /hello/.test("hello")
	const methodTwo = /hello/.exec("hello") // returns an iterator
	return methodOne && !!methodTwo
}
import { assertEquals } from '../testHelper.js';
assertEquals(twoMethods(), true, "done")

Clone this wiki locally