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

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.