Skip to main content
added 134 characters in body
Source Link
hwnd
  • 70.9k
  • 4
  • 100
  • 135

You first want to use non-greedy quantifiers, removingmake the optional part from+ operators non-greedy. Then instead of making the third capturing group and placingoptional, simply place that group inside of the nonNon-capturing group leaving the Non-capturing group optional.

/{\?if ([^{}]+)}(.+?)(?:{\?else}(.+?))?{\?endif}/g 

Live DemoLive Demo

You want to use non-greedy quantifiers, removing the optional part from the third capturing group and placing that group inside of the non-capturing group.

/{\?if ([^{}]+)}(.+?)(?:{\?else}(.+?))?{\?endif}/g 

Live Demo

You first want to make the + operators non-greedy. Then instead of making the third capturing group optional, simply place that group inside of the Non-capturing group leaving the Non-capturing group optional.

/{\?if ([^{}]+)}(.+?)(?:{\?else}(.+?))?{\?endif}/g 

Live Demo

Source Link
hwnd
  • 70.9k
  • 4
  • 100
  • 135

You want to use non-greedy quantifiers, removing the optional part from the third capturing group and placing that group inside of the non-capturing group.

/{\?if ([^{}]+)}(.+?)(?:{\?else}(.+?))?{\?endif}/g 

Live Demo