Enter visible characters (remove spaces, carriage return...)
QRegExp rxp("^\\w+\\S+$");
IP Regular Expression
QRegExp rxp("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
Port number regular expression
QRegExp rxp("^([0-9]|[1-9]\\d|[1-9]\\d{2}|[1-9]\\d{3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])$");
0-100 with two decimal places regular expression
QRegExp rxp("^(100|0?[0-9]?\\d(\\.\\d{1,2})?)$");
Enter numbers only
QRegExp rxp("^[0-9]*$");
Applications:
1 QRegExp rxp( " ^\\w+\\S+$ " ); // Enter visible characters (remove spaces and carriage returns...) 2 QRegExpValidator *pRep = new QRegExpValidator(rxp, this ); 3 ui->lineEdit_ProjectName-> setValidator(pRep);
matches non-negative integers (positive integers + 0)
^\d+$
matches positive integers
^[0-9]*[1-9][0-9]*$
matches non-positive integers (negative integers + 0)
^((-\d+)|(0+))$
matches negative integers
^-[0-9]*[1-9][0-9]*$
match integer
^-?\d+$
matches non-negative floats (positive floats + 0)
^\d+(\.\d+)?$
matches a positive floating point number
^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$
matches non-positive floats (negative floats + 0)
^((-\d+(\.\d+)?)|(0+(\.0+)?))$
matches negative floating point numbers
^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$
match float
^(-?\d+)(\.\d+)?$
Match a string of 26 English letters
^ [A-Za-z] + $
Match a string consisting of uppercase 26 English letters
^[A-Z]+$
Match a string consisting of lowercase 26 English letters
^[a-z]+$
Match a string consisting of numbers and 26 English letters
^ [A-Za-z0-9] + $
Match a string consisting of numbers, 26 English letters or underscores
^\w+$
match email address
^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$
match url
^[a-zA-z]+: // 匹配 (\ w+(-\ w+)*) (\. (\ w+(-\ w+)*))*(\? \ S*)? $
match html tag
<\s*(\S+)(\s[^>]*)?>(.*?)<\s*\/\1\s*>