正規表現を使用して、行継続文字「_」を使用するソース文字列から次を抽出するにはどうすればよいですか。行継続文字は、その行の最後の文字でなければならないことに注意してください。また、検索は文字列の最後から開始し、最初に見つかった "(" で終了する必要があります。これは、テキストの最後で何が起こっているのかだけに関心があるためです。
必要な出力:
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)
)
"