Reputation: 65
I'm trying to use this regex pattern Subject: [\a-zA-Z_0-9]+
in c++ to get this line of text from two different files one being this:
Message-ID: <..>
Subject: AAAI-22 General Information
MIME-Version: 1.0
Content-Type: multipart/alternative; ..
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
and the other being
Subject: Re: Possible need for … 240
Thread-Topic: Possible need for printout for .. 240
however, the regex pattern matches:
Subject: AAAI-22 General Information MIME-Version: 1.0
Content-Type: multipart/alternative; ..Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
for the first text file and for the second file the pattern matches
Subject: Re: Possible need for
All I want my regex pattern to search for and print out is the Subject:
and whatever else is in that line and nothing else. How can I do that using regex_search
and regex_replace
patterns?
Upvotes: 1
Views: 59
Reputation: 471
You can use this regex pattern to search for Subject line
"Subject: .+"
Explanation:
Subject:
matches the characters Subject:
literally (case
sensitive).
.
matches any character (except for line terminators)
+
matches the previous token between one and unlimited times
Upvotes: 1