Want to match what is after "subject" or "subject:" but only on that line
I want to search all lines for subject or subject:
But if the rest of the line is blank not match
(?i)(?<=\bSubject:?\s+).+$
Sample text
Subject: Pat Sanders
(line break between Subject: and Pat)
That regex is matching Pat Sanders.
Since it is on the next line I do NOT want it to match.
The regex is compiled with RegexOptions.Multiline
I think the .+
is greedy and consuming the line break.
This works in that it only matches on the current line:
(?i)(?<=\bsubject:).+?$
But this does not work:
(?i)(?<=\bsubject:?).+?$
The lookback does not consume the :
The : is included in the match
尝试这可能会工作
(\b(subject)\b).+(?=\s+\r?$)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.