View Full Version : RegExp Question

12th July 2010, 17:32
Hello! I'm trying to figure out regexp for a line that contains starts in itself. For example some of the lines may start with ***HELLO and then continue with something else where stars are the actual stars symbols:

!HELLO - This is the first line
(HELLO) - Thi is is the second line
***HELLO - is the third line
HELLO - This is the fourth line

In this text I need to locate line # 3. How can I do it with the regexp? I have tried:

QRegExp rx("***HELLO*");
statLineIndex = statFile.indexOf(rx);
QMessageBox::about(0, "test", QString::number(statLineIndex));

but, of course I keep getting first and second line and can't deffirentiate the starts, first three mean the actual star symbols and the last one is any characters. How do I diffirentiate those?

12th July 2010, 18:57
You have to escape the stars with a backslash! and for your case better split the text into lines (QStringList), loop through the list and look if they start with an asterisk. using startsWith().

EDIT: And you have to put a "." before the last asterisks.

12th July 2010, 19:04
...and don't use the Wildcard semantics.

12th July 2010, 20:33
Thank you very much. That worked for me just fine.