C# 如何使用正则表达式提取行连续的文本?
如何使用正则表达式从使用行连续字符的源字符串中提取以下内容。注意,行连续字符必须是该行的最后一个字符。此外,搜索应从字符串的结尾开始,并在遇到第一个字符串时终止。那是因为我只对课文末尾发生的事情感兴趣 想要的输出:C# 如何使用正则表达式提取行连续的文本?,c#,regex,C#,Regex,如何使用正则表达式从使用行连续字符的源字符串中提取以下内容。注意,行连续字符必须是该行的最后一个字符。此外,搜索应从字符串的结尾开始,并在遇到第一个字符串时终止。那是因为我只对课文末尾发生的事情感兴趣 想要的输出: var1, _ var2, _ var3 资料来源: ... Func(var1, _ var2, _ var3 试试这个 解释 试试这个 解释 (?<=Func\()(?<match>(?:[^\r\n]+_\r\n)+[^\r
var1, _
var2, _
var3
资料来源:
...
Func(var1, _
var2, _
var3
试试这个
解释
试试这个
解释
(?<=Func\()(?<match>(?:[^\r\n]+_\r\n)+[^\r\n]+)
@"
(?<= # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind)
Func # Match the characters “Func” literally
\( # Match the character “(” literally
)
(?<match> # Match the regular expression below and capture its match into backreference with name “match”
(?: # Match the regular expression below
[^\r\n] # Match a single character NOT present in the list below
# A carriage return character
# A line feed character
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
_ # Match the character “_” literally
\r # Match a carriage return character
\n # Match a line feed character
)+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
[^\r\n] # Match a single character NOT present in the list below
# A carriage return character
# A line feed character
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
"