简体   繁体   English

AvalonEdit:正则表达式捕获XSHD文件中的组

[英]AvalonEdit: Regex Capturing Groups in XSHD-File

i´m trying to realize a Syntax-Highlighting for a Heredoc-similar Syntax. 我正在尝试为类似Heredoc的语法实现语法高亮显示。 therefore i have to capture the starting-name. 因此我必须捕获起始名称。 but i failed (trying it in a Rule and a Span). 但是我失败了(在规则和跨度中尝试)。 This is my Regex: 这是我的正则表达式:

(?:([A-Z]{3,}))(.|\n)*?\1

The regex works in a regex-tester. 正则表达式适用于正则表达式测试程序。

But if i put it in the XSHD-Definition i get the error: 但是,如果我将其放入XSHD-Definition中,则会收到错误消息:

Error at line 128:
"(?:([A-Z]{3,}))(.|\n)*?\1" wird analysiert - Verweis auf die nicht definierte Gruppenzahl 1.

it says that the groupnumber 1 isn´t defined. 它表示未定义组号1。

does somebody know the reason? 有人知道原因吗? and how to realize the matching? 以及如何实现匹配?

thank you 谢谢

AvalonEdit is using RegexOptions.ExplicitCapture , so you'll have to use named capture groups. AvalonEdit正在使用RegexOptions.ExplicitCapture ,因此您必须使用命名捕获组。

However, what you are trying to do is not possible in AvalonEdit. 但是,您在AvalonEdit中无法实现的目标。 Rules cannot be multi-line, and the span end cannot use backrefences to the span start. 规则不能是多行的,并且跨度端不能使用backrefences到span开始。

This is because the highlighting engine highlights each line individually, and will only re-highlighting changed lines when the user is editing text. 这是因为突出显示引擎单独突出显示每一行,并且仅在用户编辑文本时重新突出显示更改的行。 To support HEREDOC constructs, AvalonEdit would need to store the results of named capture groups as part of the span stacks, and would need to support some special syntax so that the span end regex could use backreferences to those stored results. 为了支持HEREDOC结构,AvalonEdit需要将命名捕获组的结果存储为span堆栈的一部分,并且需要支持一些特殊语法,以便span end regex可以使用对这些存储结果的反向引用。

"(?:([A-Z]{3,}))(.|\n)*?\1"

Hmm, the first parenthetical (?: ) is a non-capturing group, for when you want to group (say for the | operator), but you don't care to 'remember' it. 嗯,第一个括号(?:)是一个非捕获组,用于您想要分组的时间(例如|运算符),但是您不必在乎“记住”它。 The second parenthetical, what you want to be group #1, is inside that one: ([AZ]{3,}) . 第二个括号,你想成为第一组,就在那一个里面: ([AZ]{3,}) It would seem to be logical that by saying "don't remember what is inside this", it won't. 通过说“不记得这里面是什么”似乎是合乎逻辑的,它不会。

Anyway, what is the point of the doubled up groups, with the outer being non capturing? 无论如何,双重组的重点是什么,外部是非捕获? (also no need for comma when you don't specify the second part of the quantifier sequence) Can't you just say: (当你没有指定量词序列的第二部分时也不需要逗号)你不能只说:

"([A-Z]{3})[.\n]*?\1"   //now \1 is defined?

as far as your THIRD group, (.|\\n)*? 至于你的第三组, (.|\\n)*? , in which you've used grouping+alternation+quantifiers all at once, well I have no idea what \\3 might be if you tried to access it in the original expression: [.\\n]*? ,其中您一次使用了分组+替代+量词,所以我不知道如果您尝试使用原始表达式[.\\n]*?来访问\\ 3,那可能是\\ 3 [.\\n]*? should be fine. 应该没事。

*? *?

repeats the back-reference itseft. 重复向后引用iteft。

how about 怎么样

(?:([AZ]{3,}))[.\\n]*?\\1 (?:([AZ] {3,}))[\\ n]的?* \\ 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM