gpt4 book ai didi

.net - 正则表达式查找未注释掉的标签之间的文本

转载 作者:行者123 更新时间:2023-12-02 15:09:49 25 4
gpt4 key购买 nike

我有一个简单的场景似乎难倒了我。我想获取两个未注释掉的标签之间的文本。这是一个例子:

// Example of commented text
// :Start
// <I don't want to get this text>
// :End


:Start
<Here is the text i want>
:End

解决方案:

感谢大家的帮助。非常快地收到了答案,并且完全满足了我的需要。我使用以下正则表达式,因为它最适合我的情况。特别感谢蒂姆·皮茨克:

(?sm)(?<=^:Start\s*)(?:(?!^:End).)*

最佳答案

试试这个:

(?sm)(?<=^:Start\s*)(?:(?!^:End).)*

说明:

(?sm)     # Set options: . matches newline, ^ matches start-of line
(?<= # Assert that this regex can be matched before the current position:
^ # Start of line
:Start # :Start
\s* # Any whitespace
) # End of lookahead
(?: # Try to match...
(?! # (unless the following regex could be matched here:)
^ # Start of line
:End # :End
) # End of lookahead
. # ... any character
)* # Repeat any number of times

关于.net - 正则表达式查找未注释掉的标签之间的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12804865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com