score:0

a regex isn't able to dynamically parse a character string. let me explain: it's not possible to capture a dynamically variable number of groups.

however, this regex can match the "title" group and the first "parameters" group:

/ {#--\s+(.*?)\s+#}\s+?{#@@\s+((?:.|\n)+?)\s+#} /gm

if you wan to match all {#@@ xxx #}groups, you must know in advance the maximum number of possible cases. it can be done with a regex like this (in case of max two parameters):

/ {#--\s+(.*?)\s+#}\s+?{#@@\s+((?:.|\n)+?)\s+#}(?:\s+?{#@@\s+((?:.|\n)+?)\s+#})? /gm

otherwise, you must do it in two steps:

  • capturing all {#@@ xxx #} by {#-- xxx #} in a global group
  • spliting this group by {#@@ xxx #} parts.

for further explanation, the first regex shown above can be splitted into two parts:

  • {#--\s+(.*?)\s+#} for capturing {#-- xxx #} in the group(1)
  • {#@@\s+((?:.|\n)+?)\s+#} for capturing {#@@ xxx #} in the group(2)

Related Query

More Query from same tag