Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
586 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...