Re: Regular exp
-
Hi all,
I am using Qprocess to start another process which gives me the following output from the started process.
\n\n+HTTPACTION:0,200,15\n\nAT+HTTPREAD\n\n\n\n+HTTPREAD:15\n\nHead_Light_On \n\n\nOK\n\n \r\n\n"
I want only Head_Light_On from the above output, i am using regular exp to match the output and send that particular output to one of my qml file. but i am not getting how to get that particular output using reg exp.
Can anyone help me in this matter.Thank you.
-
Hi all,
I am using Qprocess to start another process which gives me the following output from the started process.
\n\n+HTTPACTION:0,200,15\n\nAT+HTTPREAD\n\n\n\n+HTTPREAD:15\n\nHead_Light_On \n\n\nOK\n\n \r\n\n"
I want only Head_Light_On from the above output, i am using regular exp to match the output and send that particular output to one of my qml file. but i am not getting how to get that particular output using reg exp.
Can anyone help me in this matter.Thank you.
-
Hi @Naveen_D
The answer highly depends on how mutable the rest of the string is. E.g. if the rest is always the same or of the same length just search at the position.
-Michael.
@m.sue No, the rest of the string is not same it depends on the server, what command i am receiving, i want a generic reg exp for this.
this is the code i am tryingconst QRegularExpression regXp("HTTPREAD:15\n\n\\s*(.+)"); const auto regXpMatch = regXp.match(processOut); if(regXpMatch.hasMatch()){ qDebug() << "Output of regular exp is: "<< regXpMatch.captured(1); }
but in the above the number "15" is not same, every time it changes when the data from the sever changes.
-
Hi,
\d+
means one or more number. Don't forget to double the\
in your string. -
To add to @m-sue, the QRegularExpression Example also provides a good tool to test and validate your regular expressions.