Expression
var regex = new Regex(@"{([A-z]*)(([^]|:)((\\:)|[^:])*?)(([^]|:)((\\:)|[^:])*?)}");
Breakdown
The expression is [crudely] designed to find tokens within an input, using the format: {name[:pattern[:format]]}, where the pattern and format are optional.
{
([A-z]*) // name
(([^]|:)((\\:)|[^:])*?) // regex pattern
(([^]|:)((\\:)|[^:])*?) // format
}
Additionally, the expression attempts to ignore escaped colons, thus allowing for strings such as {Time:\d+\:\d+\:\d+:hh\:mm\:ss}
Question
When testing on RegExr.com, everything works sufficiently, however when attempting the same pattern in C#, the input fails to match, why?
(Any advice for general improvements to the expression are very welcome too)
[A-z]matches more than letters.Every character that is betweenZandain ASCII table.[^]isn’t valid in .NET regular expressions. (It should throw an exception, though, I think?)