Updated
I need help with a regex that will find a "@[..[...]]" pattern.
I will try to explain.
----------------------
A text will contain placeholders which will be replaced with values upon display of that very same text.
A place holder has 3 parts;
- an open tag, starts with "@[" followed by "a dot delimited text" and ends with "[",
- a property list, a "comma separated list" with qouted (double qoutes) values,
- a close tag, "]]".
The property list items can contain one or many placeholders (nested) and both double qoutes (escaped) and brackets.
The regex must overcome the issues with nested placeholders by knowing when it reached the end of the "outer" placeholder as well as any escaped qoutes and brackets.
Sample
------
Consider the following text fragment:
Linklist
@[Link.AppText["[startpage]", "startpage"]]
@[Link.Text["[startpage] loggedin", "The \"@[Text.AppText["startpage"]]\" for users"]]
@[Link.Text["@[Link["startpage"]]", "@[Text.AppText["startpage"]]"]]
The text fragment match should look like this:
match 1 = @[Link.AppText["[startpage]", "startpage"]]
Gr.1 = Link.AppText
Gr.2 = "[startpage]", "startpage"
match 2 = @[Link.Text["[startpage] loggedin", "The \"@[Text.AppText["startpage"]]\" for users"]]
Gr.1 = Link.Text
Gr.2 = "[startpage] loggedin", "The \"@[Text.AppText["startpage"]]\" for users"
match 3 = @[Link.Text["@[Link["startpage"]]", "@[Text.AppText["startpage"]]"]]
Gr.1 = Link.Text
Gr.2 = "@[Link["startpage"]]", "@[Text.AppText["startpage"]]"
With suggestion (by @ridgerunner from another community) I came this far:
@\[([._\w]+)\[([^[\]""]*(?:""[^""]*""[^[\]""]*)*)\]\]
@\[ # Outer open delimiter.
([._\w]+) # 1:st group.
\[ # Inner open delimiter.
( # Start of 2:nd group.
[^[\]""]*(?:""[^""]*""[^[\]""]*)* # Contents.
) # End of 2:nd group.
\]\] # Close delimiter.
Which gives the following result
match 1 = @[Link.AppText["[startpage]", "startpage"]]
Gr.1 = Link.AppText
Gr.2 = "[startpage]", "startpage"
match 2 = @[Text.AppText["startpage"]]
Gr.1 = Text.AppText
Gr.2 = "startpage"
match 3 = @[Link.Text["@[Link["startpage"]]", "@[Text.AppText["startpage"]]"]]
Gr.1 = Link.Text
Gr.2 = "@[Link["startpage"]]", "@[Text.AppText["startpage"]]"
As you can see it doesn't match the wanted result. Match 2 is wrong.
BUT, if I change the escaped qoutes (from \" to "") I get this result:
match 1 = @[Link.AppText["[startpage]", "startpage"]]
Gr.1 = Link.AppText
Gr.2 = "[startpage]", "startpage"
match 2 = @[Link.Text["[startpage] loggedin", "The ""@[Text.AppText["startpage"]]"" for users"]]
Gr.1 = Link.Text
Gr.2 = "[startpage] loggedin", "The ""@[Text.AppText["startpage"]]"" for users"
match 3 = @[Link.Text["@[Link["startpage"]]", "@[Text.AppText["startpage"]]"]]
Gr.1 = Link.Text
Gr.2 = "@[Link["startpage"]]", "@[Text.AppText["startpage"]]"
Left to solve is how to make it work with both "escaped" and "doubled" qoutes.
As discussed with Sergey (see below), I updated this question and of course a combination of regex and a parser could make things more fail-safe .. and .Net's "Balanced groups" might be an alternative as well.