Regular Expression in QT

Source: Internet
Author: User

Regular Expressions in QT are similar to regular expressions in perl. The QRegExp class in QT implements regular expressions.

 

Public member functions:

Public member functions are classified into three types:

1. Constructor

1. The default constructor, QRegExp (), generates an empty Regular Expression object.

2. copy constructor, QRegExp (const QRegExp & patten)

3. schema constructor, QRegExp (const QString &Pattern, Qt: casesensiti.pdfCS= Qt: CaseSensitive, PatternSyntaxSyntax= RegExp) to generate a regular expression object for the specified matching mode.

2. obtain the information and matching information of the regular expression object.

1. isValid (): checks whether the regular expression is valid and returns true if it is valid. Otherwise, false is returned.

Cpp Code {
Dp. sh. Toolbar. CopyToClipboard (this); return false;
} "Href =" http://writeblog.csdn.net/# ">
  1. Qregexp exp1 ("C [9]");
  2. BoolValid = exp1.isvalid (); // return true
  3. Qregexp exp1 ("C [9 ");
  4. BoolValid = exp1.isvalid (); // return false
QRegExp exp1 ("c [9]"); bool valid = exp1.isValid (); // return true QRegExp exp1 ("c [9"); bool valid = exp1.isValid (); // return false

2. errorString ()

Check whether there is an error in the regular expression, similar to isValid. If there is an error, "no error occurred" is returned, and "unexpected end" is returned"

3. isEmpty (): determines whether the regular expression is null. When the default constructor is used to generate the regular expression, this function returns true; otherwise, false.

Cpp Code {
Dp. sh. Toolbar. CopyToClipboard (this); return false;
} "Href =" http://writeblog.csdn.net/# ">
  1. Qregexp exp1;
  2. BoolValid = exp1.isempty (); // return true
QRegExp exp1; bool valid = exp1.isEmpty (); // return true

4. isMinimal ()

During regular expression capturing, the quantifiers are captured at least. Unlike perl, each captured attribute can be specified in perl, while qt must have the same attributes for all captured items.

 

5. casesensiti.pdf ()

Check whether the regular expression is case sensitive.

 

6. cap (), capturedTexts ()

The former obtains each captured item, and the index starts from 1. The latter obtains the entire capture list.

7. exactMatch (QString), returns whether the whole string matches, and returns false if some matches.

 

8. indexIn (). If it is successful, index is returned. If it is unsuccessful,-1 is returned.

9. lastIndexIn (), matching from the back

 

10. matchedLength () returns the length of the matched string.

 

11. numCaptures () to obtain the number of items captured in the regular expression.

 

12. pattern () to obtain the regular expression itself

 

13. patternSyntax ()

  • EnumPatternsyntax{RegExp, RegExp2, Wildcard, FixedString}
  • The default value is RegExp.

     

    14. pos

    Obtain the index of the regular expression or capture item in the matching string. 0 indicates the index of the entire regular expression, 1 indicates the position of capture item 1, and so on.

     

    3. Set the parameters of the regular expression.

    1. setminimal (bool), see isminimal

    2. setcasesensititive (). The parameter QT: caseinsensitive is case insensitive. The parameter QT: casesensitive is case sensitive. The default value is sensitive.

    3. setpattern (), see pattern ()

    4. setpatternsyntax (), see patternsyntax ()

     

    Another: 1. Regular objects support operators =, = ,! = Heavy load.

    2. The common parts of regular expressions are not described. They are similar to Perl, but Perl uses the most refreshing regular expressions.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.