如何使用 regex_search 从两个不同的 .txt 文件中获取一行文本
我正在尝试在 c++ 中使用此正则表达式模式 Subject: [\a-zA-Z_0-9]+
从两个不同的文件中获取这一行文本,一个是这样的:
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
另一个
Subject: Re: Possible need for … 240
Thread-Topic: Possible need for printout for .. 240
是,正则表达式模式匹配:
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
对于第一个文本文件和第二个文件,模式匹配
Subject: Re: Possible need for
我希望我的正则表达式模式搜索并打印出来的是 Subject:
以及该行中的其他内容以及没有别的。如何使用 regex_search
和 regex_replace
模式来做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用此正则表达式模式来搜索主题行
说明:
Subject:
与字符Subject:
字面匹配(大小写敏感)。
.
匹配任何字符(行终止符除外)+
匹配前一个标记一次到无限次You can use this regex pattern to search for Subject line
Explanation:
Subject:
matches the charactersSubject:
literally (casesensitive).
.
matches any character (except for line terminators)+
matches the previous token between one and unlimited times