The example php regex (below) uses subroutine calls to work.
If I try use it with the C# Regex
class I get an error: Unrecognized grouping construct
Is it possible to rewrite this in to C# regex syntax?
Would it be a simple translation, or does another (regex) approach need to be used?
If it is not possible what is the name of the thing it is using, so I can add it to this question to make it more useful to others with the same problem?
PHP which works with all json RFC test data
$pcre_regex = '
/
(?(DEFINE)
(?<number> -? (?: [1-9]\d*| 0 ) (\.\d+)? (e [+-]? \d+)? )
(?<boolean> true | false | null )
(?<string> " (?>[^"\\\\]+ | \\\\ ["\\\\bfnrt\/] | \\\\ u [0-9a-f]{4} )* " )
(?<array> \[ (?: (?&json) (?: , (?&json) )* )? \s* \] )
(?<pair> \s* (?&string) \s* : (?&json) )
(?<object> \{ (?: (?&pair) (?: , (?&pair) )* )? \s* \} )
(?<json> \s* (?: (?&number) | (?&boolean) | (?&string) | (?&array) | (?&object) ) \s* )
)
\A (?&json) \z
/six
';
And not working in C#
string pattern = @"(?(DEFINE)
(?<number> -? (?: [1-9]\d* | 0 ) (\.\d+)? (e [+-]? \d+)? )
(?<boolean> true | false | null )
(?<string> "" (?>[^""\\\\]+ | \\\\ [""\\\\bfnrt\/] | \\\\ u [0-9a-f]{4} )* "" )
(?<array> \[ (?: (?&json) (?: , (?&json) )* )? \s* \] )
(?<pair> \s* (?&string) \s* : (?&json) )
(?<object> \{ (?: (?&pair) (?: , (?&pair) )* )? \s* \} )
(?<json> \s* (?: (?&number) | (?&boolean) | (?&string) | (?&array) | (?&object) ) \s* ))
\A (?&json) \z
";
string input = @"[{\"Example\": \"data\"}]";
RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline;
bool isValid = Regex.IsMatch(input, pattern, options);
Edit: This question is NOT about using regex with json, it is about how to do something (subroutine calls) in C#, which CAN be done in PHP regex
Just because there is a way of parsing json in C# DOES NOT answer the question. Please keep your answers and comments on topic.