I want to match something like a LaTeX function with optional parameters in PHP.
Following examples should match the pattern:
example{arg0}
example{arg0}{opt1}
example{arg0}{opt1}{opt2}
example{arg0}{opt1}{opt2}{opt3}
As you can see first parameter is required but following parameters (opt1-3) are optional.
I got this one:
/example\{(.*)\}(\{(.*)\})?(\{(.*)\})?(\{(.*)\})?/U
But it's only matching the first parameters (see regex101).
What RegEx will recognize each line as match and parameters opt1-3 as groups?
(..)??or don't use U. You could also consider using a negated character class instead of lazy.*, like[^}\n\r]*Uist not working (tried that before). But doubling all the question marks did the trick! Thank you very much :) If you put it as answer I'll choose and upvote.