Navigate back to the homepage

How to use regex in typescript?

Infinitbility
TypeScript
October 31st, 2021 · 1 min read
How to use regex in typescript?

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.

  1. Regex to get true or false
  2. Regex to get match value
  3. Regex to get no of occurrence match value

Let start today tutorial How to use regex in typescript?

Regex to get true or false

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/;
3
4regex.test(str);

Output

Regex, test, example

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/;
3
4str.match(regex);

Output

Regex, match, example

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;
3
4str.match(regex).length;

Output

Regex, match, globally, example

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.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo

Tutorials

Categories

More articles from Infinitbility

How to check type of variable in typescript?

How to check type of variable in typescript?

Example of check datatype of variable in typescript

October 29th, 2021 · 1 min read
How to convert number to string in typescript?

How to convert number to string in typescript?

Example of number to string conversion in typescript

October 28th, 2021 · 1 min read
© 2020–2021 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]