我在我的正则表达式身体中发现了这些东西,但我不知道我能用它们做什么.有人有例子,所以我可以尝试了解它们是如何工作的吗?
(?!) - negative lookahead
(?=) - positive lookahead
(?<=) - positive lookbehind
(?<!) - negative lookbehind
(?>) - atomic group
Run Code Online (Sandbox Code Playgroud) 我在C#程序中有以下正则表达式,并且难以理解它:
(?<=#)[^#]+(?=#)
Run Code Online (Sandbox Code Playgroud)
我会把它分解为我认为我理解的内容:
(?<=#) a group, matching a hash. what's `?<=`?
[^#]+ one or more non-hashes (used to achieve non-greediness)
(?=#) another group, matching a hash. what's the `?=`?
Run Code Online (Sandbox Code Playgroud)
所以这个问题我已经是?<=和?<组成部分.从阅读MSDN,?<name>用于命名组,但在这种情况下,尖括号永远不会关闭.
我?=在文档中找不到,搜索它真的很难,因为搜索引擎大多会忽略那些特殊的字符.