正则表达式捕获多个字符串占位符

时间:2016-03-21 14:50:36

标签: regex

我正在尝试编写一个正则表达式来捕获字符串中{alphabetical}的所有出现(例如,让它为无,一个或多个),例如:

  • This is a {variable} - > [variable]
  • This is a {variable} and this is {another} one - > [variable, another]
  • This is a {variable} and this is {another} {one} - > [variable, another, one]

我设法做/(\{[a-z]+})/(在此测试:https://regex101.com/),但它只捕获了第一次出现。请帮助我捕捉所有出现并将其捕捉到群组中。

1 个答案:

答案 0 :(得分:1)

要捕获更多出现次数,请使用g标记:regex101.com/r/cE3aQ1/1