QRegExp的用法
bool QRegExp::exactMatch(const QString &str) const
Returns true if str is matched exactly by this regular expression; otherwise returns false. You can determine how much of the string was matched by calling matchedLength().
For a given regexp string R, exactMatch("R") is the equivalent of indexIn("^R$") since exactMatch() effectively encloses the regexp in the start of string and end of string anchors, except that it sets matchedLength() differently.
代码:
QRegExp reg("^.+.mp3$");
if (!reg.exactMatch(fi.fileName()))
{
continue;
}
要判断fi的filename是不是“.map”格式的。
^的作用:
^ |
The caret signifies the beginning of the string. If you wish to match a literal ^ you must escape it by writing \\^. For example, ^#include will only match strings which begin with the characters '#include'. (When the caret is the first character of a character set it has a special meaning, see Sets of Characters.) |
简单总结:起始符,如果要加入^,就用\\^
$的作用:
$ |
The dollar signifies the end of the string. For example \d\s*$ will match strings which end with a digit optionally followed by whitespace. If you wish to match a literal $ you must escape it by writing \\$. 简单总结:终止符,同上。 |