javascript, regex parse string content in curly brackets

后端 未结 5 1221
忘掉有多难
忘掉有多难 2020-12-31 03:19

i am new to regex. I am trying to parse all contents inside curly brackets in a string. I looked up this post as a reference and did exactly as one of the answers suggest, h

5条回答
  •  醉梦人生
    2020-12-31 03:44

    Try this:

    var abc = "test/abcd{string1}test{string2}test" //any string
    var regex = /{(.+?)}/g //g flag so the regex is global
    abc.match(regex) //find every match
    

    a good place to read about Regex in javascript is here, and a nice place to test is here

    good luck!

提交回复
热议问题