[Interest] format of QString

André Somers andre at familiesomers.nl
Fri Apr 4 13:58:10 CEST 2014


R. Reucher schreef op 4-4-2014 13:47:
> A slight modification to your proposed reg-exp:
>
> QRegExp regExp("(m|c)_([0-9]{6})\\.rcp");

For new (Qt 5) code, I really recommend using QRegularExpression instead 
of QRegExp where possible.

André

>
> Regards, René
>
> On Friday 04 April 2014 13:25:36 Etienne Sandré-Chardonnal wrote:
>> Hi sarah,
>>
>> This is untested but should work:
>>
>> QRegExp regExp("(m|c)_([0-9]{6}).rcp");
>> if(regExp.exactMatch(fileName))
>> {
>>      //Here we know that filename matches the pattern
>>      QString letter = regExp.cap(1);    //Will be "m" or "c"
>>      QString number = regExp.cap(2);    //Will contain the six digits as a
>> string
>> }
>>
>>
>> Regular expressions are a vast topic, you will find a lot of documentation
>> by googling it.
>>
>>
>> Etienne
>>
>> 2014-04-04 13:01 GMT+02:00 André Somers <andre at familiesomers.nl>:
>>>   sarah jones schreef op 4-4-2014 12:47:
>>> Hi
>>> How would you advise that I ensure a QString object is of a given format.
>>> In particular I want to check that a QString conforms to the following
>>> m_ or c_
>>> followed by 6 digits (0-9)
>>> followed by ".rcd"
>>>
>>> so m_000001.rcd matches as does c_000003.rcd
>>> but not m_aa00002.rcd
>>> etc
>>>
>>> A regular expression sounds like the right tool for that. See
>>> QRegularExpression (Qt5) or QRegExp (Qt4).
>>>
>>> André
>>>
>>>
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest




More information about the Interest mailing list