-1

I need a greedy regex to select everything between curly braces but not the starting and ending curly braces for example:

{here {first} and {second} and {third}}

output should be {first}, {second} {third}

Rahul
  • 249
  • 2
  • 12

1 Answers1

2

{[^{]+?} would work for your test case. However, this won't support arbitrary nesting, which is not possible with regex. If that's what you're looking for, you'll need a parser.

Example: https://regex101.com/r/GrqGdS/1

Edit:

if { is written at places where the cardinality operator cannot occur, there is no need to escape it.

Mene
  • 3,739
  • 21
  • 40