I have a text like that:
asd dsa [SKU].[Analytic5].&[omg wtf] not found blah blah blah "&[omg wtf]". Query Text: <ccon>SELECT {[SKU].[Analytic5].&[omg wtf]} ON 0 FROM [Model_week] CELL PROPERTIES CELL_ORDINAL</ccon>
I need to extract [SKU].[Analytic5].&[omg wtf] from there. Actually it’s [SKU].[*].&[*].
I made this regex:
\[SKU\]\.\[.*\]\.\&\[.*\]
It works… kind of… it grabs all the junk after first [omg wtf] until the final [Model_week] met.
So the result of my regex is:
[SKU].[Analytic5].&[omg wtf] not found blah blah blah "&[omg wtf]". Query Text: <ccon>SELECT {[SKU].[Analytic5].&[omg wtf]} ON 0 FROM [Model_week]
I just can’t understand how to limit it. I tried things like putting {1}, but it doesn’t help.
>Solution :
The RegEx quantifier * is a greedy quantifier with a lazy equivalent *?.
The difference between greedy and lazy quantifiers is that the greedy quantifier will try to match as many characters as possible whereas lazy quantifier will try to match least characters possible.
The effect of this in your example is that [.*\] matches everything from the first [ to the last ]. But if you change those quantifiers to their lazy equivalents your RegEx will work as you intended.
The example below with lazy quantifiers will match what you expect it to match:
\[SKU\]\.\[.*?\]\.\&\[.*?\]
Output of the RegEx above when used on your snippet:
[SKU].[Analytic5].&[omg wtf]