sách gpt4 ai đã đi

C++正则表达式搜索多行注释(/* */之间)

In lại 作者:太空宇宙 更新时间:2023-11-04 14:50:05 44 4
mua khóa gpt4 Nike

我正在尝试实现简单的案例(基本上是在两个标签之间查找文本,无论它们是什么)。我要排队

/* 我的评论1 */

/* 我的评论2 */

/* 我的评论3 */

作为输出。似乎我需要将捕获组限制为 1?因为在字符串 Hello/* my comment 1 */world 上我得到了我想要的 - res[0] contains/* my comment 1 */

#include 
#include
#include

int main(int argc, const char * argv[])
{
std::string str = "Hello /* my comment 1 */ world /* my comment 2 */ of /* my comment 3 */ cpp";

std::cmatch res;
std::regex rx("/\\*(.*)\\*/");

std::regex_search(str.c_str(), res, rx);

for (int i = 0; i < sizeof(res) / sizeof(res[0]); i++) {
std::cout << res[i] << std::endl;
}

trả về 0;
}

44 4 0
太空宇宙
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com