gpt4 book ai didi

c++ - 如何使用 QT RegExp 从字符串中提取子字符串列表

转载 作者:行者123 更新时间:2023-11-28 03:11:21 25 4
gpt4 key购买 nike

如何使用 QT RegExp 从字符串中提取子字符串列表,例如,如果我有此输入字符串 "qjkfsjkdfn 54df#Sub1#sdkf++sdf#Sub2#q qfsdf445#Sub3#sdf"我想使用 "(#.+# )" 正则表达式。

最佳答案

您可以使用以下代码:

QRegExp rx("#([^#]+)#"); // create the regular expression
string text = "qjkfsjkdfn 54df#Sub1#sdkf ++sdf #Sub2#q qfsdf445#Sub3#sdf";
int pos = 0;
while ( (pos = rx.search(text, pos)) != -1 ) // while there is a matching substring
{
cout << rx.cap(1); // output the text captured in group 1
}

关于c++ - 如何使用 QT RegExp 从字符串中提取子字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18374694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com