Originally Posted by
MatrixSan
I am really bad in regular expressions, but with QRegularExpression and with an example in your firs post should work something like this:
If I understand you correctly.
Thank you. Let me try...
Originally Posted by
anda_skoa
Thank you, that's ideal. But in my case I reading a log file, read line by line and need detect line has data match the regex
Added after 29 minutes:
I need detect string contain "indicator1", "para1=", "para2=" (they have fixed value) and then I capture their values
(eg I need detect website action: http://site.com?INDICATOR.PHP?someth...ET=targettolog...)
Added after 40 minutes:
Originally Posted by
MatrixSan
I am really bad in regular expressions, but with QRegularExpression and with an example in your firs post should work something like this:
QString str
= "(indicators1)somethings¶1=value1¶2=value2 &something";
QRegularExpression exp("((?<=\\()(.*?)(?=\\)))|((?<=\\&)(.*?)(?=\\=))|((?<=\\=)(.*?)(?=\\&))");
QRegularExpressionMatchIterator i = exp.globalMatch(&str);
while (i.hasNext())
{
QRegularExpressionMatch expMatch = i.next();
if (expMatch.hasMatch())
{
result.append(expMatch.captured(0));
}
}
QStringList result;
QString str = "(indicators1)somethings¶1=value1¶2=value2 &something";
QRegularExpression exp("((?<=\\()(.*?)(?=\\)))|((?<=\\&)(.*?)(?=\\=))|((?<=\\=)(.*?)(?=\\&))");
QRegularExpressionMatchIterator i = exp.globalMatch(&str);
while (i.hasNext())
{
QRegularExpressionMatch expMatch = i.next();
if (expMatch.hasMatch())
{
result.append(expMatch.captured(0));
}
}
To copy to clipboard, switch view to plain text mode
If I understand you correctly.
Thank for your suggestion. Now I have code that works as expected
QString str
= "haha:site.com:hehe¶1=value1¶2=value2&hihi";
QRegularExpression re("site.com:(.*?)¶1=(?<para1value>.*?)¶2=(?<para2value>.*?)&");
QRegularExpressionMatch match = re.match(&str);
if (match.hasMatch()) {
qDebug()<<match.captured("para1value")<<"|"<<match.captured("para2value");
}
QString str = "haha:site.com:hehe¶1=value1¶2=value2&hihi";
QRegularExpression re("site.com:(.*?)¶1=(?<para1value>.*?)¶2=(?<para2value>.*?)&");
QRegularExpressionMatch match = re.match(&str);
if (match.hasMatch()) {
qDebug()<<match.captured("para1value")<<"|"<<match.captured("para2value");
}
To copy to clipboard, switch view to plain text mode
result:
"value1" | "value2"
"value1" | "value2"
To copy to clipboard, switch view to plain text mode
Bookmarks