Regular Expression to get a string between parentheses in Javascript

后端 未结 9 770
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 09:45

I am trying to write a regular expression which returns a string which is between parentheses. For example: I want to get the string which resides between the strings \"(\"

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 10:09

    Alternative:

    var str = "I expect five hundred dollars ($500) ($1).";
    str.match(/\(.*?\)/g).map(x => x.replace(/[()]/g, ""));
    
    → (2) ["$500", "$1"]
    

    It is possible to replace brackets with square or curly brackets if you need

提交回复
热议问题