Reputation: 1414
How can I extract the following from the source string that uses line continuation character "_" using Regex. Note, the line continuation character must be the last character on that line. Also, the search should start from the end of the string and terminate at the first "(" encountered. That's because I am only interested what's happening at the end of the text.
Wanted Output:
var1, _
var2, _
var3
Source:
...
Func(var1, _
var2, _
var3
Upvotes: 1
Views: 495
Reputation: 11181
Try this
(?<=Func\()(?<match>(?:[^\r\n]+_\r\n)+[^\r\n]+)
Explanation
@"
(?<= # 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)
)
"
Upvotes: 6