QRegExp: get the parsed string
I have for example this string:
"DLH3029 (LUFTHANSA THREE ZERO TWO NINER)"
that should become:
'LUFTHANSA THREE ZERO TWO NINER'
so I use this regex:
Code:
echo "DLH3029 (LUFTHANSA THREE ZERO TWO NINER)" | sed "s/[^(]*(\([^)]*\)).*/'\1'/"
How can now use it in a Qt program ?
I've tried but I cannot find a way to make it work.
Re: QRegExp: get the parsed string
Re: QRegExp: get the parsed string
Thanks but:
Code:
QRegExp rx
("s/[^(]*(\([^)]*\)).*/'\1'/");
rx.indexIn("DLH3029 (LUFTHANSA THREE ZERO TWO NINER)");
qDebug() << "list: " << list;
::exit(1);
result:
Quote:
list: ("", "", "")
What am I doing wrong ?
Re: QRegExp: get the parsed string
Ehm s/[^(]*(\([^)]*\)).*/'\1'/ are two "commands". One for searching and one for replacing. For Qt you have to split them. QRegExp expects the search part. And also note that they are not 100% Perl compatible, but that is all in the docs... (Qt5 supports 100% Perl compatible expressions, if you want to use the newly published Alpha release.)
Re: QRegExp: get the parsed string
Ah ok. The regex is a part of a bigger one so I have to split it further.
My company is thinking about upgrading to Qt5 so this is a good reason to do it now.
Thanks a lot Lykurg.
Re: QRegExp: get the parsed string
Upgrading a commercial development project to alpha software is probably not the best idea. Nothing in your requirement needs the Perl regex compatibility changes AFAICT.
Also, be careful to escape backslashes in the string literals.
Re: QRegExp: get the parsed string
I don't have the URL's right now, but there was a test that the QRegExp class is really slow. That was also the reason for changing this class in Qt5. So even if you do not need the additional syntax a change to Qt5 (when ready) can pay off, if your application heavily rely on regular expressions.
EDIT: That was not the URL I was thinking of but anyway: http://qt-project.org/wiki/Regexp_engine_in_Qt5