QT中,怎样写才能让正则表达式支持中文匹配?
例如:我想匹配 "我...的" (以“我”开头,以“的”结尾)的词组,
试了一下 "我.*的" ,结果一个单词都匹配不出来。请问这个正则表达式应该怎么写呢?
不知道我的问题问清楚了没有?
------解决方案--------------------
QRegExp直接支持中文的
- C/C++ code
QString str = "我是的 我不的"; QRegExp rx("(我[^ ]*的)"); QStringList list; int pos = 0; while ((pos = rx.indexIn(str, pos)) != -1) { list << rx.cap(1); pos += rx.matchedLength(); } qDebug() << list;
------解决方案--------------------
\xhhhh Matches the Unicode character corresponding to the hexadecimal number hhhh (between 0x0000 and 0xFFFF).