Matthew Lock
Matthew Lock

Reputation: 13476

Is there anything like perl's Regexp::Grammars or labeled subpatterns in .NET?

I really like perl's Regexp::Grammars module. Is there anything like this for .NET?

I'd really like to use a recursive descent parser in a regex style way (eg searching for a matching pattern through a large document) in C#, and be able to express that pattern recursively.

Update After reading this little gem from brian d foy, I discovered that perl 5.10 supports labeled subpatterns using (?&NAME). PCRE now has a Nuget package, and PCRE supports named/labeled subpatterns.

Upvotes: 4

Views: 187

Answers (2)

daxim
daxim

Reputation: 39158

Perl5 Regexp::Grammars is modeled after Perl6 grammars.

Niecza is a Perl6 implementation that implements grammars and targets the CLI, which .NET also does.

Upvotes: 5

Tim Pietzcker
Tim Pietzcker

Reputation: 336148

I don't think that there is a comparable module, but you can create recursive regexes in .NET. See here for an example.

Upvotes: 2

Related Questions