I am creating a program where I offer a few functions that can be entered by the user. Let's say I have a function to convert a string to upper-case with the function $upper(string)
and a function $lower(string)
. The user can enter those in a text box while using placeholders to insert content (e.g. %T for the title of a song). Using both placeholders and functions, the user can enter a complete naming pattern.
Functions can be nested and I want to execute the inner-most function first. Now I am looking for a Regex to identify it. In english, I am looking for a function (and its value) that does not contain another function.
During my tests, I use hyphens instead of brackets and no $-sign. This is a lot easier to read. So the functions during testing are lower-sometext-
.
This is my guess so far:
(lower|upper)-(?!((lower|upper)-.*-))-
I read it as follows:
- find the word
upper
orlower
, - followed by a hyphen,
- followed by anything that is NOT the word
upper
orlower
, a hyphen, a random number of random characters and a hyphen - followed by a hypen.
But that won't even accept lower-sometext-
. I am trying different things for more than 2 hours but I can't figure it out...