简体   繁体   中英

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

\{{(.*?)\}}

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

Try the following:

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

it works for

{{text is here}}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM