如何使用 regex_search 从两个不同的 .txt 文件中获取一行文本

发布于 2025-01-10 05:56:50 字数 1006 浏览 3 评论 0原文

我正在尝试在 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_searchregex_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2025-01-17 05:56:50

您可以使用此正则表达式模式来搜索主题行

"Subject: .+"

说明:

  • Subject: 与字符 Subject: 字面匹配(大小写
    敏感)。

  • .匹配任何字符(行终止符除外)

  • + 匹配前一个标记一次到无限次

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文