bhylu.com

Advertisements

JS RegExp Assertions

Assertions check a position without consuming a character. Anchors require the match to begin or end at a boundary.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

console.log(/^open$/i.test("OPEN"));
console.log(/^open$/i.test("open now"));

What happens

Only the whole-word input matches this anchored pattern.