In this article, we’ll look at the
RegExp constructor lets us search and manipulate text.
A regex consists of a pattern to use and match the text.
It can optionally contain zero or more modifiers to provide more instructions on how the pattern should be used.
For instance, we can use the
RegExp constructor by writing:
const re = new RegExp("c.*t");
We have a regex that matches a word with some letters in between
. means any character.
* means preceding whatever comes after.
We can add some modifiers called flags to change the regex.
Some flags include:
ifor ignoring case
So if we have:
const re = new RegExp("c.*t", 'gmi');
We can check that it does global match with the
re.global should return
The property can’t be set, so assigning a value to it won’t change the value.
RegExp instances have some methods.
They include the
test checks whether a string matches the regex pattern.
exec returns the string the matches the regex.
We can call
test by running;
then we get
But we call:
then we get
true because of the case-insensitive match.
exec , we can write:
Then we get:
With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...
You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...
Top 10 Web Development Trends in 2020 will provide you with a detailed list of the trends which are currently being noticed. Upskilling to these trends will help you in landing onto better jobs in 2020-2021.