Opt Prutal
Opt Prutal

Reputation: 484

Get all strings between two curly braces using regex in javascript

I need to get an array of all strings that are contained in curly brackets using JavaScript.

 {{text is here}} 

note that the text could contain all special characters and could be multi line i have tried this so far regex test

\{{(.*?)\}}

Upvotes: 0

Views: 66

Answers (2)

revo
revo

Reputation: 48711

In your demo you enabled m flag which is a wrong flag here. You need s flag or even without flags:

{{([^]*?)}}

Note: You don't need to escape braces here.

Live demo

Upvotes: 2

Ted
Ted

Reputation: 4067

Try the following:

(?<=\{{)(.*?)(?=\}})

it works for

{{text is here}}

https://regex101.com/r/gYXSbO/7/

Upvotes: 1

Related Questions