text: The QRegExp class provides pattern matching using regular expressions. More...
  #include <QRegExp>
  Note: All5'. Quantifiers can be made non-greedy, see setMinimal().
  Parentheses allow us to group elements together so that we can quantify and capture them. For example if we have the expression mail|letter|correspondence that matches a string we know that one of the words matched but not which one. Using parentheses allows us to "capture" whatever is matched within their bounds, so if we used (mail|letter|correspondence) and matched this regexp against the string "I sent you some email" we can use the cap() or capturedTexts() functions to extract the matched characters, in this case 'mail'.
  We can use captured text within the regexp itself. To refer to the captured text we use backreferences which are indexed from 1, the same as for cap(). For example we could search for duplicate words in a string using \b(\w+)\W+\1\b which means match a word boundary followed by one or more word characters followed by one or more non-word characters followed by the same text as the first parenthesized expression followed by a word boundary.
  If we want to use parentheses purely for grouping and not for capturing we can use the non-capturing syntax, e.g. (?:green|blue). Non-capturing parentheses begin '(?:' and end ')'. In this example we match either 'green' or 'blue' but we do not capture the match so we only know whether or not we matched but not which color we actually found. Using non-capturing parentheses is more efficient than using capturing parentheses since the regexp engine has to do less book-keeping.
  Both capturing and non-capturing parentheses may be nested.
  For historical reasons, quantifiers (e.g. *) that apply to capturing parentheses are more "greedy" than other quantifiers. For example, a*(a)* will match "aaa" with cap(1) == "aaa". This behavior is different from what other regexp engines do (notably, Perl). To obtain a more intuitive capturing behavior, specify QRegExp::RegExp2 to the QRegExp constructor or call setPatternSyntax(QRegExp::RegExp2).
  When the number of matches cannot be determined in advance, a common idiom is to use cap() in a loop. For example:
  QRegExp rx("(\\d+)"); QString str = "Offsets: 12 14 99 231 7"; QStringList list; int pos = 0; while ((pos = rx.indexIn(str, pos)) != -1) { list << rx.cap(1); pos += rx.matchedLength(); } // list: ["12", "14", "99", "231", "7"]
  Assertions make some statement about the text at the point where they occur in the regexp but they do not match any characters. In the following list E stands for any expression.
  Most command shells such as bash or cmd.exe support "file globbing", the ability to identify a group of files by using wildcards. The setPatternSyntax() function is used to switch between regexp and wildcard mode. Wildcard matching is much simpler than full regexps and has only four features:
  For example if we are in wildcard mode and have strings which contain filenames we could identify HTML files with *.html. This will match zero or more characters followed by a dot followed by 'h', 't', 'm' and 'l'.
  To test a string against a wildcard expression, use exactMatch(). For example:
  QRegExp rx("*.txt"); rx.setPatternSyntax(QRegExp::Wildcard); rx.exactMatch("README.txt"); // returns true rx.exactMatch("welcome.txt.bak"); // returns false
  Most of the character class abbreviations supported by Perl are supported by QRegExp, see characters and abbreviations for sets of characters.
  In QRegExp, apart from within character classes, ^ always signifies the start of the string, so carets must always be escaped unless used for that purpose. In Perl the meaning of caret varies automagically depending on where it occurs so escaping it is rarely necessary. The same applies to $ which in QRegExp always signifies the end of the string.
  QRegExp's quantifiers are the same as Perl's greedy quantifiers (but see the note above). Non-greedy matching cannot be applied to individual quantifiers, but can be applied to all the quantifiers in the pattern. For example, to match the Perl regexp ro+?m requires:
  QRegExp rx("ro+m"); rx.setMinimal(true);
  The equivalent of Perl's /i option is setCaseSensitivity(Qt::CaseInsensitive).
  Perl's /g option can be emulated using a loop.
  In QRegExp . matches any character, therefore all QRegExp regexps have the equivalent of Perl's /s option. QRegExp does not have an equivalent to Perl's /m option, but this can be emulated in various ways for example by splitting the input into lines or by looping with a regexp that searches for newlines.
  Because QRegExp is string oriented, there are no \A, \Z, or \z assertions. The \G assertion is not supported but can be emulated in a loop.
  Perl's $& is cap(0) or capturedTexts()[0]. There are no QRegExp equivalents for $`, $' or $+. Perl's capturing variables, $1, $2, ... correspond to cap(1) or capturedTexts()[1], cap(2) or capturedTexts()[2], etc.
  To substitute a pattern use QString::replace().
  Perl's extended /x syntax is not supported, nor are directives, e.g. (?i), or regexp comments, e.g. (?#comment). On the other hand, C++'s rules for literal strings can be used to achieve the same:
  QRegExp mark("\\b" // word boundary "[Mm]ark" // the word we want to match );
  Both zero-width positive and zero-width negative lookahead assertions (?=pattern) and (?!pattern) are supported with the same syntax as Perl. Perl's lookbehind assertions, "independent" subexpressions and conditional expressions are not supported.
  Non-capturing parentheses are also supported, with the same (?:pattern) syntax.
  See QString::split() and QStringList::join() for equivalents to Perl's split and join functions.
  Note: because C++ transforms \'s they must be written twice in code, e.g. \b must be written \\b. rx.indexIn("Hello world"); // returns -1 (no match) rx.indexIn("This_is-OK"); // returns 0 (matched at position 0)
  The second string matches 'This_is-OK'. We've used the character set abbreviation '\S' (non-whitespace) and the anchors to match strings which contain no whitespace.
  In the following example we match strings containing 'mail' or 'letter' or 'correspondence' but only match whole words i.e. not 'email'
  QRegExp rx("\\b(mail|letter|correspondence)\\b"); rx.indexIn("I sent you an email"); // returns -1 (no match) rx.indexIn("Please write the letter"); // returns 17
  The second string matches "Please write the letter". The word 'letter' is also captured (because of the parentheses). We can see what text we've captured like int pos = 0; // where we are in the string int count = 0; // how many Eric and Eirik's we've counted while (pos >= 0) { pos = rx.indexIn(str, pos); if (pos >= 0) { ++pos; // move along in str ++count; // count our Eric or Eirik } }
  We've used the indexIn() function to repeatedly match the regexp in the string. Note that instead of moving forward by one character at a time pos++ we could have written pos += rx.matchedLength() to skip over the already matched string. The count will equal 3, matching 'One Eric another Eirik, and an Ericsson. How many Eiriks, Eric?'; it doesn't match 'Ericsson' or 'Eiriks' because they are not bounded by non-word boundaries.
  One common use of regexps is to split lines of delimited data into their component fields.
  str = "Nokia Corporation and/or its subsidiary(-ies)\t\tNorway"; QString company, web, country; rx.setPattern("^([^\t]+)\t([^\t]+)\t([^\t]+)$"); if (rx.indexIn(str) != -1) { company = rx.cap(1); web = rx.cap(2); country = rx.cap(3); }
  In this example our input lines have the format company name, web address and country. Unfortunately the regexp is rather long and not very versatile -- the code will break if we add any more fields. A simpler and better solution is to look for the separator, '\t' in this case, and take the surrounding text. The QString::split() function can take a separator string or regexp as an argument and split a string accordingly.
  QStringList field = str.split("\t");
  Here field[0] is the company, field[1] the web address and so on.
  To imitate the matching of a shell we can use wildcard mode.
  QRegExp rx("*.html"); rx.setPatternSyntax(QRegExp::Wildcard); rx.exactMatch("index.html"); // returns true rx.exactMatch("default.htm"); // returns false rx.exactMatch("readme.txt"); // returns false
  Wildcard matching can be convenient because of its simplicity, but any wildcard regexp can be defined using full regexps, e.g. .*.html$. Notice that we can't match both .html and .htm files with a wildcard unless we use *.htm* which will also match 'test.html.bak'. A full regexp gives us the precision we need, .*\.html?$.
  QRegExp can match case insensitively using setCaseSensitivity(), and can use non-greedy matching, see setMinimal(). By default QRegExp uses full regexps but this can be changed with setWildcard(). Searching can be forward with indexIn() or backward with lastIndexIn(). Captured text can be accessed using capturedTexts() which returns a string list of all captured strings, or using cap() which returns the captured string for the given index. The pos() function takes a match index and returns the position in the string where the match was made (or -1 if there was no match).
  See also QString, QStringList, QRegExpValidator, QSortFilterProxyModel, and Regular Expression Example.=().
  Destroys the regular expression and cleans up its internal.