C++正则表达式提取子串 [英] C++ regex to extract substring
本文介绍了C++正则表达式提取子串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 C++ 中提取 * 字符之前的所有字符的子字符串.例如,如果我有一个字符串
How can I extract a substring in c++ of all the characters before a * character. For example, if I have a string
ASDG::DS"G*0asd}}345sdgfsdfg
我将如何提取部分
ASDG::DS"G
推荐答案
您当然不需要正则表达式.只需使用 std::string::find('*')代码>
和 std::string::substr代码>
:
You certainly don't need a regular expression for that. Just use std::string::find('*')
and std::string::substr
:
#include <string>
int main()
{
// raw strings require C++-11
std::string s1 = R"(ASDG::DS"G*0asd}}345sdgfsdfg)";
std::string s2 = s1.substr(0, s1.find('*'));
}
这篇关于C++正则表达式提取子串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文