I have problem similar to this issue We have custom syntax for inserting 'references', it uses double square brackets. In this brackets could be only number (either positive 1,2 or negative -2, -3).
Now the problem: we need to validate the string that contains this references. If string contains no references - it is valid. If string contains valid references - it is also valid. If at least one reference is not valid (like missing end brackets, no numerics inside) it is not valid.
I could easily create expression that match our syntax of references '[[-?[[0-9]]]' and extract them, but have no ideas how to convert it to RegExp for validation (to exclude missing end brackets, non numerics etc).
We want to use Data Annotation validation attributes in ASP.NET so that it supports C#/javascript validation at the same time out of the box. It is better to have one regex than two repeated .IndexOf solutions (which is generally not a problem to implement) on client/server side to validate.
Here is some example values:
test string valid
- valid
test string valid [[1]] [[-22]]
- valid
[[0]] test string vali[[1]][[-22]]
- valid
test[[
- invalid
test [[1[[2]]]]
- invalid
test [[1a]]
- invalid
test [[1]]]]
- invalid