I am trying to split a string using QRegExp but am having no luck. An example string of what I am looking for is:
AB-123456 or CD-123456.78. As you can see, they all will begin with 2 letters, followed by a -, followed by 6 numbers. Then a "." with 1-4 numbers is optional. Currently, I have a QString that looks as follows: "AB-123456CD-123456.78EF-123456". I need to split this into its 3 parts: AB-123456, CD-123456.78, EF-123456. Here is my code. The QStringList returns a 1-item list with the whole string returned. Any ideas.
QString text
= "AB-123456CD-123456.78EF-123456";
QRegExp rx
( "^[A-Z]{2,2}-[0-9]{6,6}(.[0-9]{1,4})?$" );
rx.
setPatternSyntax( QRegExp::Wildcard );
QString text = "AB-123456CD-123456.78EF-123456";
QRegExp rx( "^[A-Z]{2,2}-[0-9]{6,6}(.[0-9]{1,4})?$" );
rx.setPatternSyntax( QRegExp::Wildcard );
QStringList strList = text.split( rx, QString::SkipEmptyParts );
To copy to clipboard, switch view to plain text mode
I thought by using the Wildcard syntax, then the "." would just be a ".". Is this correct? I have tried it with and without the ^ and the $, but I get the same results. Any ideas why my QString isn't being split into three pieces?
Thanks!
Bookmarks