0

How do I get the first string ("firstStr" for the examples below) using QRegularExpression

QString readCmdOutput = "";
/* readCmdOutput = "firstStr\secondStr"; or 
readCmdOutput = "firstStr
secondStr
"
*/
readCmdOutput = QString::fromLocal8Bit(myProcess->readAllStandardOutput());  

QRegularExpression re("REGEXPRESSION");
QRegularExpressionMatch match = re.match(readCmdOutput);
if (match.hasMatch()) { 
   QString matched2 = match2.captured(0);  // has to contain "firstStr"
}
m7913d
  • 10,244
  • 7
  • 28
  • 56
How to
  • 103
  • 1
  • 11

1 Answers1

1

The correct regular expression is:

QRegularExpression re("[^\\n\\\\]*");

This regular expression matches every sequence of characters not containing a line break (\n) or a backslash (\). Note that you have to escape all backslashes. See QRegularExpression for more details.

m7913d
  • 10,244
  • 7
  • 28
  • 56