匹配双引号"用\"匹配单引号'用'
如()[]{}/|\-+匹配[用\\[匹配]用\\]匹配\用\\\\匹配/用\\/匹配|用\\|匹配-用\\-匹配+用\\+
匹配大写英文或小写英文或数字或下划线用\\w或0-9a-zA-Z_
中括号[]表示匹配单个字符,匹配中扩号里列出的任意一个字符
1 |
[dsa]//匹配d或s或a |
小括号()表示匹配字符串,匹配小扩号里列出的所有字符构成的字符串
1 |
(dsaff) //仅能匹配dsaff |
大括号{}表示匹配的次数,放于()或[]之后
1 |
[dsa]{1,8}//匹配1-8次[dsa],如匹配d,dd,dddddddd |
1 |
(dsa){1,8}//匹配1-8次(dsa),如匹配dsa,dsadsadsadsadsadsadsadsa |
1 2 3 4 5 |
QRegExp re("^[\\w~!@#$%^&*()+`={}:;<>?,.|'\"\[\\]\\-\\/\\\\]+$");
QString test("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`1234567890-=~!@#$%^&*()_+[]{}|;:'\"\\/,.<>?");
bool match = re.exactMatch(test); //match=true |
1 2 3 4 5 |
QRegExp reg("^(\\-(?!0(?!\\.))|\\+(?!0(?!\\.)))?(0|[1-9]\\d*)(\\.\\d+)?$");
QString test("41424.4155346");
bool match = re.exactMatch(test); //match=true |
1 2 3 4 5 |
QRegExp reg("^(\\+(?!0(?!\\.)))?(0|[1-9]\\d*)(\\.\\d+)?$");
QString test("41424.4155346");
bool match = re.exactMatch(test); //match=true |
1 2 3 4 5 |
QRegExp reg("^(\\+)?(0(?=\\.)|[1-9]\\d*)(\\.\\d+)?$");
QString test("41424.4155346");
bool match = re.exactMatch(test); //match=true |
1 2 3 4 5 |
QRegExp reg("^(\\-(?!0)|\\+(?!0))?(0|[1-9]\\d*)$");
QString test("414246");
bool match = re.exactMatch(test); //match=true |
1 2 3 4 5 |
QRegExp reg("^(\\+(?!0))?(0|[1-9]\\d*)$");
QString test("414246");
bool match = re.exactMatch(test); //match=true |
1 2 3 4 5 |
QRegExp reg("^(\\+)?([1-9]\\d*)$");
QString test("414246");
bool match = re.exactMatch(test); //match=true |
1 2 3 4 5 6 7 8 9 |
QRegExp reg("^[\\w~!@#$%^&*()+`={}:;<>?,.|'\"\[\\]\\-\\/\\\\]+$"); if (!reg.exactMatch(value.data())) { message_ = QObject::tr("The password can only contanin numbers, English " "characters or special characters ") .toStdString(); return false; } return true; |