Sometimes, we want to match exact string with JavaScript.
In this article, we’ll look at how to match exact string with JavaScript.
How to match exact string with JavaScript?
To match exact string with JavaScript, we use the ^
and $
characters in the regex.
For instance, we write
const r = /^a$/;
to create the regex r
that matches ‘a’ exactly.
^
means the start of the string and $
means the end of the string.
Conclusion
To match exact string with JavaScript, we use the ^
and $
characters in the regex.