Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

regex - What is PCRE-compatible syntax? And is C# PCRE-compatible?

What is PCRE-compatible syntax? And is C# PCRE-compatible? From wikipedia I found this:

Perl Compatible Regular Expressions (PCRE) is a regular expression C library inspired by the regular expression capabilities in the Perl programming language, written by Philip Hazel, starting in summer 1997. PCRE's syntax is much more powerful and flexible than either of the POSIX regular expression flavors and many classic regular expression libraries. The name is misleading, because PCRE and Perl each have capabilities not shared by the other.

Source

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

C# regexes share some syntax with PCRE regexes. Most of the features overlap but both libraries keep their own specifics:

A couple examples:

PCRE

  • Supports recursion
  • Supports backtrack control verbs
  • Supports constructs like (?(DEFINE) ... )
  • Supports more options
  • Offers a DFA parsing mode
  • Supports partial matches
  • Supports K
  • Supports X++ shorthand syntax (equivalent of (?>X+))

.NET

  • Supports capture stacks and duplicate named groups
  • Supports balancing groups
  • Supports variable length lookbehind

This list is not exhaustive. You can compare both flavours on this page and the sibling pages.

Given the differences, I wanted to be able to use PCRE regexes from .NET and recently started PCRE.NET, which is a wrapper project. It's not finished yet but is starting to be usable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...