Categories
JavaScript Answers

How to use regex to get string between curly braces with JavaScript?

Spread the love

Sometimes, we want to use regex to get string between curly braces with JavaScript.

In this article, we’ll look at how to use regex to get string between curly braces with JavaScript.

How to use regex to get string between curly braces with JavaScript?

To use regex to get string between curly braces with JavaScript, we can use the /{(.*?)}/ regex.

For instance, we write

const re = /{(.*?)}/;

to use the re regex to get the string between curly braces.

We use (.*?) inside the curly braces to match anything inside the curly braces.

Conclusion

To use regex to get string between curly braces with JavaScript, we can use the /{(.*?)}/ regex.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *