Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt QRegExp捕获和替换_Qt_Qregexp - Fatal编程技术网

Qt QRegExp捕获和替换

Qt QRegExp捕获和替换,qt,qregexp,Qt,Qregexp,我有一根绳子 @echo Setting environment for using the GDAL Utilities. set GDAL_PATH="G:\MapTiler" @echo GDAL path is %GDAL_PATH%. set PATH=%GDAL_PATH%;%PATH% 在本文中,我想提取“G:\MapTiler”并将其替换为“c:\gdal\bin” 为此,我需要QRegExp 谢谢您应该为此使用QString::replace(

我有一根绳子

    @echo Setting environment for using the GDAL Utilities.
    set GDAL_PATH="G:\MapTiler"
    @echo GDAL path is %GDAL_PATH%.
    set PATH=%GDAL_PATH%;%PATH%
在本文中,我想提取“G:\MapTiler”并将其替换为“c:\gdal\bin”

为此,我需要QRegExp


谢谢

您应该为此使用QString::replace()方法:

QString gdalPath;
gdalPath.replace(QRegExp("G:\\MapTiler"),"c:\\gda\\bin");
但如果被替换的字符串甚至没有更改,请不要使用正则表达式,请使用字符串替换:

gdalPaht.replace("G:\\MapTiler","c:\\gda\\bin");
编辑以更改路径:

QString::replace(QRegExp("set GDAL_PATH=\"[^\"]*\""),"set GDAL_PATH=\"c:\\gda\\bin\"");

实际上,“G:\MapTiler”和“c:\\gda\\bin”不是固定的,它可以是任何路径,然后使用
QString::replace(QRegExp(“set-GDAL\u-PATH=”[^\“]*\”),“set-GDAL\u-PATH=”c:\\gda\\bin\”;
括号
[^\“]*
表示除双qoute符号外的任何东西。嗨,塞巴斯蒂安,我需要类似的QRegExp(“GDAL\u-PATH=”*”);刚刚编辑了注释来解释括号,应该可以:)在这里我可以找到各种各样的Qregexp示例