Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用正则表达式提取行连续的文本?_C#_Regex - Fatal编程技术网

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)
)
"