qt QRegExp

          

The QRegExp class provides pattern matching using regular expressions.

A regular expression, or "regexp", is a pattern for matching substrings in a text. This is useful in many contexts, e.g.,

Validation

A regexp can test whether a substring meets some criteria, e.g. is an integer or contains no whitespace.

Searching

A regexp provides more powerful pattern matching than simple substring matching, e.g., match one of the words mailletter orcorrespondence, but none of the words emailmailmanmailerletterbox, etc.

Search and Replace

A regexp can replace all occurrences of a substring with a different substring, e.g., replace all occurrences of & with & except where the & is already followed by an amp;.

String Splitting

A regexp can be used to identify where a string should be split apart, e.g. splitting tab-delimited strings.

A brief introduction to regexps is presented, a description of Qt's regexp language, some examples, and the function documentation itself. QRegExp is modeled on Perl's regexp language. It fully supports Unicode. QRegExp can also be used in a simpler, wildcard modethat is similar to the functionality found in command shells. The syntax rules used by QRegExp can be changed withsetPatternSyntax(). In particular, the pattern syntax can be set to QRegExp::FixedString, which means the pattern to be matched is interpreted as a plain string, i.e., special characters (e.g., backslash) are not escaped.

A good text on regexps is Mastering Regular Expressions (Third Edition) by Jeffrey E. F. Friedl, ISBN 0-596-52812-4.

  QRegExp这个类提供了用常规的表达模式搭配。一个常规的表达,是搭配子字符串。这是非常有用的在上下文中。

  一个简短的介绍,一些列子这些函数文档。QRegExp是一个模型。它完全支持unicode.QRegExp也能被用于

Regexps are built up from expressions, quantifiers, and assertions. The simplest expression is a character, e.g. x or 5. An expression can also be a set of characters enclosed in square brackets. [ABCD] will match an A or a B or a C or a D. We can write this same expression as [A-D], and an experession to match any captital letter in the English alphabet is written as [A-Z].

A quantifier specifies the number of occurrences of an expression that must be matched. x{1,1} means match one and only one x.x{1,5} means match a sequence of x characters that contains at least one x but no more than five.

Note that in general regexps cannot be used to check for balanced brackets or tags. For example, a regexp can be written to match an opening html <b> and its closing </b>, if the <b> tags are not nested, but if the <b> tags are nested, that same regexp will match an opening <b> tag with the wrong closing </b>. For the fragment <b>bold <b>bolder</b></b>, the first <b> would be matched with the first </b>, which is not correct. However, it is possible to write a regexp that will match nested brackets or tags correctly, but only if the number of nesting levels is fixed and known. If the number of nesting levels is not fixed and known, it is impossible to write a regexp that will not fail.

 Regexps 被建立与表达式,数量词和断言


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值