0

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

\{{(.*?)\}}
Opt Prutal
  • 384
  • 4
  • 14
  • Possible duplicate of [Regex Match all characters between two strings](https://stackoverflow.com/questions/6109882/regex-match-all-characters-between-two-strings) – phuzi Mar 13 '18 at 09:42

2 Answers2

2

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

revo
  • 47,783
  • 14
  • 74
  • 117
1

Try the following:

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

it works for

{{text is here}}

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

Ted
  • 3,985
  • 1
  • 20
  • 33