Qt notes-basic use of regular expressions (only get numbers)

This is mainly when the mobile phone verification code is obtained, and it is simply processed using Qt regular expressions.

Take notes. Easy to copy code and modify later

 

code show as below:

        QRegExp rx("(\\d+)");  // 匹配数字
        QString vail = "";
        int pos = 0;
        while ((pos = rx.indexIn(str.split("|")[1], pos)) != -1) {
            
            vail += rx.cap(0);
            pos += rx.matchedLength();
        }
        vail = vail.left(vail.size() - 2);

Here str.split ("|") [1] is the content of the obtained mobile phone message.

Here vail = vail.left (vail.size ()-2) here depends on the specific verification code, I will prompt for 10 minutes and it will take up 2 characters. So we have to subtract 2

1343 original articles were published · 10,000+ praises · 4.35 million views

Guess you like

Origin blog.csdn.net/qq78442761/article/details/105610436