Match exact string JavaScript

Last Updated On Monday 8th Nov 2021

Regex Match Whole String

Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects.

Regex Match Entire String

A regular expression pattern is composed of simple characters, such as /abc/, or a combination of simple and special characters, such as /ab*c/ or /Chapter (\d+)\.\d*/.

	let str = 'Hello 456 World 123';
let regex1 = /\b(World)\b/g;
let regex2 = /\b(world)\b/g;

console.log(str.match(regex1)); // [ 'World' ]
console.log(str.match(regex2)); // null
	let str = 'abc'
let pat = /^abc$/g;