Hello Friends 👋,
Welcome To Infinitbility! ❤️
This tutorial will help you to use Regular expressions ( regex ) in typescript, here we will learn below three points in typescript regex.
- Regex to get
- Regex to get match value
- Regex to get no of occurrence match value
Let start today tutorial How to use regex in typescript?
Regex to get
We have the
.test() method, it will return
true when the string matches or false if not.
1let str: string = "Welcome to Infinitbility";2let regex: object = /to/;34regex.test(str);
Regex to get match value
We have the
.match() method to get match content from a string.
1let str: string = "Welcome to Infinitbility";2let regex: object = /to/;34str.match(regex);
Regex to get no of occurance match value
Multiple times we want to know how many times the same string repeating in our data.
we have to change only regex globally like the below code example. it will provide an array of match content.
1let str: string = "Welcome to to Infinitbility";2let regex: object = /to/g;34str.match(regex).length;
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.