• 6978阅读
  • 3回复

QRegExp类中"\\s+"看不太明白? [复制链接]

上一主题 下一主题
离线lijasmine
 
只看楼主 倒序阅读 楼主  发表于: 2006-04-20
在 QRegExp 类中写到:
QRegExp rx( "^\\S+$" );   // match strings without whitespace就是与没有空格的匹配吧。
在QString类中提到:
QString line( "forename\tmiddlename surname \t \t phone" );
QRegExp sep( "\s+" );
QString s = line.section( sep, 2, 2 ); // s == "surname"我能理解

如果start或者end为负数,我们就从字符串的右面开始计数,最右面的是-1,接着是-2,依此类推。

QString line( "forename\tmiddlename surname \t \t phone" );
QRegExp sep( "\\s+" );
QString s = line.section( sep, -3, -2 ); // s == "middlename surname"我不太明白?
[ 此贴被XChinux在2006-04-20 16:26重新编辑 ]
离线billdates
只看该作者 1楼 发表于: 2006-04-20
4 comments:

1. (From http://doc.trolltech.com/4.1/qregexp.html): Note: The C++ compiler transforms backslashes in strings, so to include a \ in a regexp, you will need to enter it twice, i.e. \\. To match the backslash character itself, you will need four: \\\\.
2. \S and \s are different
3. " \t \t " is multiple white spaces, i.e., matched by ONE "\\s+"
4. You probably neglected "+" in "\\s+" and were thinking about "\\s"?
离线lijasmine
只看该作者 2楼 发表于: 2006-04-21
Thank you very much!
QRegExp sep( "\s+" ); means what? I am in a puzzle here.
QRegExp sep( "\\s+" ); means one more whitespace
[ 此贴被lijasmine在2006-04-21 21:13重新编辑 ]
离线tsuibin

只看该作者 3楼 发表于: 2009-08-21
正则表达式啦~
\是特殊字符 所以需要转译\\
\s是空格span
快速回复
限100 字节
 
上一个 下一个