• 4775阅读
  • 2回复

正则表达式怎么定 [复制链接]

上一主题 下一主题
离线pengyizhao2
 

只看楼主 倒序阅读 楼主  发表于: 2014-07-15
我有很多这种规则的数据/usb1/1-3/1-3.1/1-3.1.2/1-3.1.2:1.5"因为有些数据后面是每有:的,我只想要匹配usb1到:这种数据格式,如果不是有usb1和:就过滤掉,
怎么定正则表达式
离线dosmlp

只看该作者 1楼 发表于: 2014-07-15
正则表达式是这样/usb.*\d:
在qt中这样定义
QRegExp PRL("/usb.*\\d:");
PRL.setMinimal(true);//最小匹配

检查是否有匹配到
  1. bool QRegExp::exactMatch(const QString & str) const
  2. 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().
  3. 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.
  4. For example, if the regular expression is blue, then exactMatch() returns true only for input blue. For inputs bluebell, blutak and lightblue, exactMatch() returns false and matchedLength() will return 4, 3 and 0 respectively.
  5. Although const, this function sets matchedLength(), capturedTexts(), and pos().


离线pengyizhao2

只看该作者 2楼 发表于: 2014-07-16
谢谢
快速回复
限100 字节
 
上一个 下一个