Closed adamchester closed 9 years ago
Here is a link to an online (ECMAScript) version of the regex.
It looks like {{UHOH}}
is a problem, as I understand the double-braces should be "escaped" into a single brace in the output.
Here is an updated Regex which matches {{
and }}
so they can be replaced with {
and }
([^{]
(?<start_prop>\{)
(?<destr>\@|\$)?
(?<property>[\w\.\[\]]+)
(?<align>,[^:}]+)?
(?<format>:[^}]+)?
(?<end_prop>\})+)
|
(?<double_open>\{\{)
|
(?<double_close>\}\})
with the input:
I sat at {@Chair.whatever.whatever} {{{{UHOH}}
Just biting '{@Fruit}' number "#{@Count:abc}"
Income was {Income} at {@Da te:d}
Welcome, customer #{$CustomerId,-10}, pleasure to see you
Welcome, customer #{CustomerId,-10:000000}, pleasure to see you
{place}, {0}
{1}, {Place}
{{blahblah}}
Replacement format: DO=${double_open}, DC=${double_close}, S=${start_prop}, D=${destr}, P=${property}, A=${align}, F=${format}, E=${end_prop}
Gives the output:
DO=, DC=, S={, D=@, P=Chair.whatever.whatever, A=, F=, E=}
DO={{, DC=, S=, D=, P=, A=, F=, E=
DO={{, DC=, S=, D=, P=, A=, F=, E=
DO=, DC=}}, S=, D=, P=, A=, F=, E=
DO=, DC=, S={, D=@, P=Fruit, A=, F=, E=}
DO=, DC=, S={, D=@, P=Count, A=, F=:abc, E=}
DO=, DC=, S={, D=, P=Income, A=, F=, E=}
DO=, DC=, S={, D=$, P=CustomerId, A=,-10, F=, E=}
DO=, DC=, S={, D=, P=CustomerId, A=,-10, F=:000000, E=}
DO=, DC=, S={, D=, P=place, A=, F=, E=}
DO=, DC=, S={, D=, P=0, A=, F=, E=}
DO=, DC=, S={, D=, P=1, A=, F=, E=}
DO=, DC=, S={, D=, P=Place, A=, F=, E=}
DO={{, DC=, S=, D=, P=, A=, F=, E=
DO=, DC=}}, S=, D=, P=, A=, F=, E=
This issue records an attempt to build a regular expression which can parse/match all the properties within a message template according the "spec" (which doesn't really exist yet, but it will be basically the same as Serilog).
Tests