Qt-检查正则表达式宽度
Qt- checking regular expression width
我正试图用不同的表达式替换正则表达式,这些表达式取决于行的宽度和框的宽度。
这是我的代码:
//mangledText is my text that I've searching on it
//rx is regular expression
QRegExp rx("<lms([^<]*)/>");
while ((pos = rx.indexIn(mangledText)) != -1){
for (int j = 0; j < tempLayout->lineCount(); j++){
QTextLine tl = tempLayout->lineAt(j);
//here is width of each line
int naturalTextWidth = tl.naturalTextWidth();
//rect width is maximum width of box
if (naturalTextWidth < rectWidth)
mangledText.replace(pos, rx.matchedLength(), "replace Text");
else
mangledText.replace(pos, rx.matchedLength(), "n replace Text");
}
}
mangledText.replace('n', QChar::LineSeparator);
如果该行的文本超出了框外,我希望将正则表达式替换为"替换文本"。否则我将其替换为"替换文本"。问题是它总是会把它移到下一行。因为CCD_ 1小于CCD_。但我想检查要替换的每个正则表达式。
更新:例如:1111111111111111111 <lms8><lms3><lms2>
正在显示:
1111111111111111111<lms8>
<lms3>
<lms2>
我想要这个:
1111111111111111111<lms8><lms3><lms2>
有什么建议吗?
试试这个。
(.[^<]*)(<lms.*>)
替换为以下语法。
$1n$2
结果将是
111111111111111111111111111
<lms8><lms3><lms2>
相关文章:
- 使用正则表达式regex_search在字符串中查找字符串
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- C++正则表达式无限循环
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- 定义有趣的宏和正则表达式在Z3 C++绑定
- 带有多个字符分隔符的正则表达式
- C++ 使用增强正则表达式库时断言崩溃
- 有人可以帮助我处理正则表达式吗?
- 使用正则表达式获取大括号块的列表
- 正则表达式以匹配数字的重复模式,后跟任何类型的分隔符?
- 使用正则表达式进行范围检查
- 已检查匹配项时接收到C++正则表达式空字符串
- 检查输入字符串是否为数字且为C++,如果是,则将其转换为 int(正则表达式?
- 检查一个正则表达式是否涵盖另一个正则表达式
- Qt-检查正则表达式宽度
- 使用正则表达式检查输入的有效性
- 检查字符串是否可能与正则表达式匹配
- 用一些正则表达式检查读行
- c++正则表达式模式检查文件扩展名
- 用于检查Gomoku获胜条件的C++正则表达式