Struct qt_core::QRegExp

source ·
#[repr(C)]
pub struct QRegExp { /* private fields */ }
Expand description

The QRegExp class provides pattern matching using regular expressions.

C++ class: QRegExp.

C++ documentation:

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.,

ValidationA regexp can test whether a substring meets some criteria, e.g. is an integer or contains no whitespace.
SearchingA regexp provides more powerful pattern matching than simple substring matching, e.g., match one of the words mail, letter or correspondence, but none of the words email, mailman, mailer, letterbox, etc.
Search and ReplaceA 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 SplittingA 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 mode that is similar to the functionality found in command shells. The syntax rules used by QRegExp can be changed with setPatternSyntax(). 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.

Note: In Qt 5, the new QRegularExpression class provides a Perl compatible implementation of regular expressions and is recommended in place of QRegExp.

Implementations§

source§

impl QRegExp

source

pub unsafe fn cap_1a(&self, nth: c_int) -> CppBox<QString>

Returns the text captured by the nth subexpression. The entire match has index 0 and the parenthesized subexpressions have indexes starting from 1 (excluding non-capturing parentheses).

Calls C++ function: QString QRegExp::cap(int nth = …) const.

C++ documentation:

Returns the text captured by the nth subexpression. The entire match has index 0 and the parenthesized subexpressions have indexes starting from 1 (excluding non-capturing parentheses).


  QRegExp rxlen("(\\d+)(?:\\s*)(cm|inch)");
  int pos = rxlen.indexIn("Length: 189cm");
  if (pos > -1) {
      QString value = rxlen.cap(1); // "189"
      QString unit = rxlen.cap(2);  // "cm"
      // ...
  }

The order of elements matched by cap() is as follows. The first element, cap(0), is the entire matching string. Each subsequent element corresponds to the next capturing open left parentheses. Thus cap(1) is the text of the first capturing parentheses, cap(2) is the text of the second, and so on.

See also capturedTexts() and pos().

source

pub unsafe fn cap_1a_mut(&self, nth: c_int) -> CppBox<QString>

Returns the text captured by the nth subexpression. The entire match has index 0 and the parenthesized subexpressions have indexes starting from 1 (excluding non-capturing parentheses).

Calls C++ function: QString QRegExp::cap(int nth = …).

C++ documentation:

Returns the text captured by the nth subexpression. The entire match has index 0 and the parenthesized subexpressions have indexes starting from 1 (excluding non-capturing parentheses).


  QRegExp rxlen("(\\d+)(?:\\s*)(cm|inch)");
  int pos = rxlen.indexIn("Length: 189cm");
  if (pos > -1) {
      QString value = rxlen.cap(1); // "189"
      QString unit = rxlen.cap(2);  // "cm"
      // ...
  }

The order of elements matched by cap() is as follows. The first element, cap(0), is the entire matching string. Each subsequent element corresponds to the next capturing open left parentheses. Thus cap(1) is the text of the first capturing parentheses, cap(2) is the text of the second, and so on.

See also capturedTexts() and pos().

source

pub unsafe fn cap_0a(&self) -> CppBox<QString>

Returns the text captured by the nth subexpression. The entire match has index 0 and the parenthesized subexpressions have indexes starting from 1 (excluding non-capturing parentheses).

Calls C++ function: QString QRegExp::cap() const.

C++ documentation:

Returns the text captured by the nth subexpression. The entire match has index 0 and the parenthesized subexpressions have indexes starting from 1 (excluding non-capturing parentheses).


  QRegExp rxlen("(\\d+)(?:\\s*)(cm|inch)");
  int pos = rxlen.indexIn("Length: 189cm");
  if (pos > -1) {
      QString value = rxlen.cap(1); // "189"
      QString unit = rxlen.cap(2);  // "cm"
      // ...
  }

The order of elements matched by cap() is as follows. The first element, cap(0), is the entire matching string. Each subsequent element corresponds to the next capturing open left parentheses. Thus cap(1) is the text of the first capturing parentheses, cap(2) is the text of the second, and so on.

See also capturedTexts() and pos().

source

pub unsafe fn cap_0a_mut(&self) -> CppBox<QString>

Returns the text captured by the nth subexpression. The entire match has index 0 and the parenthesized subexpressions have indexes starting from 1 (excluding non-capturing parentheses).

Calls C++ function: QString QRegExp::cap().

C++ documentation:

Returns the text captured by the nth subexpression. The entire match has index 0 and the parenthesized subexpressions have indexes starting from 1 (excluding non-capturing parentheses).


  QRegExp rxlen("(\\d+)(?:\\s*)(cm|inch)");
  int pos = rxlen.indexIn("Length: 189cm");
  if (pos > -1) {
      QString value = rxlen.cap(1); // "189"
      QString unit = rxlen.cap(2);  // "cm"
      // ...
  }

The order of elements matched by cap() is as follows. The first element, cap(0), is the entire matching string. Each subsequent element corresponds to the next capturing open left parentheses. Thus cap(1) is the text of the first capturing parentheses, cap(2) is the text of the second, and so on.

See also capturedTexts() and pos().

source

pub unsafe fn capture_count(&self) -> c_int

Returns the number of captures contained in the regular expression.

Calls C++ function: int QRegExp::captureCount() const.

C++ documentation:

Returns the number of captures contained in the regular expression.

This function was introduced in Qt 4.6.

source

pub unsafe fn captured_texts(&self) -> CppBox<QStringList>

Returns a list of the captured text strings.

Calls C++ function: QStringList QRegExp::capturedTexts() const.

C++ documentation:

Returns a list of the captured text strings.

The first string in the list is the entire matched string. Each subsequent list element contains a string that matched a (capturing) subexpression of the regexp.

For example:

QRegExp rx(“(\d+)(\s*)(cm|inch(es)?)”); int pos = rx.indexIn(“Length: 36 inches”); QStringList list = rx.capturedTexts(); // list is now (“36 inches”, “36”, “ “, “inches”, “es”)

The above example also captures elements that may be present but which we have no interest in. This problem can be solved by using non-capturing parentheses:

QRegExp rx(“(\d+)(?:\s*)(cm|inch(?:es)?)”); int pos = rx.indexIn(“Length: 36 inches”); QStringList list = rx.capturedTexts(); // list is now (“36 inches”, “36”, “inches”)

Note that if you want to iterate over the list, you should iterate over a copy, e.g.

QStringList list = rx.capturedTexts(); QStringList::iterator it = list.begin(); while (it != list.end()) { myProcessing(*it); ++it; }

Some regexps can match an indeterminate number of times. For example if the input string is "Offsets: 12 14 99 231 7" and the regexp, rx, is (\d+)+, we would hope to get a list of all the numbers matched. However, after calling rx.indexIn(str), capturedTexts() will return the list ("12", "12"), i.e. the entire match was "12" and the first subexpression matched was "12". The correct approach is to use cap() in a loop.

The order of elements in the string list is as follows. The first element is the entire matching string. Each subsequent element corresponds to the next capturing open left parentheses. Thus capturedTexts()[1] is the text of the first capturing parentheses, capturedTexts()[2] is the text of the second and so on (corresponding to $1, $2, etc., in some other regexp languages).

See also cap() and pos().

source

pub unsafe fn captured_texts_mut(&self) -> CppBox<QStringList>

Returns a list of the captured text strings.

Calls C++ function: QStringList QRegExp::capturedTexts().

C++ documentation:

Returns a list of the captured text strings.

The first string in the list is the entire matched string. Each subsequent list element contains a string that matched a (capturing) subexpression of the regexp.

For example:

QRegExp rx(“(\d+)(\s*)(cm|inch(es)?)”); int pos = rx.indexIn(“Length: 36 inches”); QStringList list = rx.capturedTexts(); // list is now (“36 inches”, “36”, “ “, “inches”, “es”)

The above example also captures elements that may be present but which we have no interest in. This problem can be solved by using non-capturing parentheses:

QRegExp rx(“(\d+)(?:\s*)(cm|inch(?:es)?)”); int pos = rx.indexIn(“Length: 36 inches”); QStringList list = rx.capturedTexts(); // list is now (“36 inches”, “36”, “inches”)

Note that if you want to iterate over the list, you should iterate over a copy, e.g.

QStringList list = rx.capturedTexts(); QStringList::iterator it = list.begin(); while (it != list.end()) { myProcessing(*it); ++it; }

Some regexps can match an indeterminate number of times. For example if the input string is "Offsets: 12 14 99 231 7" and the regexp, rx, is (\d+)+, we would hope to get a list of all the numbers matched. However, after calling rx.indexIn(str), capturedTexts() will return the list ("12", "12"), i.e. the entire match was "12" and the first subexpression matched was "12". The correct approach is to use cap() in a loop.

The order of elements in the string list is as follows. The first element is the entire matching string. Each subsequent element corresponds to the next capturing open left parentheses. Thus capturedTexts()[1] is the text of the first capturing parentheses, capturedTexts()[2] is the text of the second and so on (corresponding to $1, $2, etc., in some other regexp languages).

See also cap() and pos().

source

pub unsafe fn case_sensitivity(&self) -> CaseSensitivity

Returns Qt::CaseSensitive if the regexp is matched case sensitively; otherwise returns Qt::CaseInsensitive.

Calls C++ function: Qt::CaseSensitivity QRegExp::caseSensitivity() const.

C++ documentation:

Returns Qt::CaseSensitive if the regexp is matched case sensitively; otherwise returns Qt::CaseInsensitive.

See also setCaseSensitivity(), patternSyntax(), pattern(), and isMinimal().

source

pub unsafe fn copy_from(&self, rx: impl CastInto<Ref<QRegExp>>) -> Ref<QRegExp>

Copies the regular expression rx and returns a reference to the copy. The case sensitivity, wildcard, and minimal matching options are also copied.

Calls C++ function: QRegExp& QRegExp::operator=(const QRegExp& rx).

C++ documentation:

Copies the regular expression rx and returns a reference to the copy. The case sensitivity, wildcard, and minimal matching options are also copied.

source

pub unsafe fn error_string(&self) -> CppBox<QString>

Returns a text string that explains why a regexp pattern is invalid the case being; otherwise returns "no error occurred".

Calls C++ function: QString QRegExp::errorString() const.

C++ documentation:

Returns a text string that explains why a regexp pattern is invalid the case being; otherwise returns “no error occurred”.

See also isValid().

source

pub unsafe fn error_string_mut(&self) -> CppBox<QString>

Returns a text string that explains why a regexp pattern is invalid the case being; otherwise returns "no error occurred".

Calls C++ function: QString QRegExp::errorString().

C++ documentation:

Returns a text string that explains why a regexp pattern is invalid the case being; otherwise returns “no error occurred”.

See also isValid().

source

pub unsafe fn escape(str: impl CastInto<Ref<QString>>) -> CppBox<QString>

Returns the string str with every regexp special character escaped with a backslash. The special characters are $, (,), *, +, ., ?, [, ,], ^, {, | and }.

Calls C++ function: static QString QRegExp::escape(const QString& str).

C++ documentation:

Returns the string str with every regexp special character escaped with a backslash. The special characters are $, (,), *, +, ., ?, [, ,], ^, {, | and }.

Example:

s1 = QRegExp::escape(“bingo”); // s1 == “bingo” s2 = QRegExp::escape(“f(x)”); // s2 == “f\(x\)”

This function is useful to construct regexp patterns dynamically:

QRegExp rx(“(” + QRegExp::escape(name) + “|” + QRegExp::escape(alias) + “)”);

See also setPatternSyntax().

source

pub unsafe fn exact_match(&self, str: impl CastInto<Ref<QString>>) -> bool

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().

Calls C++ function: bool QRegExp::exactMatch(const QString& str) const.

C++ documentation:

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().

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.

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.

Although const, this function sets matchedLength(), capturedTexts(), and pos().

See also indexIn() and lastIndexIn().

source

pub unsafe fn index_in_3a( &self, str: impl CastInto<Ref<QString>>, offset: c_int, caret_mode: CaretMode ) -> c_int

Attempts to find a match in str from position offset (0 by default). If offset is -1, the search starts at the last character; if -2, at the next to last character; etc.

Calls C++ function: int QRegExp::indexIn(const QString& str, int offset = …, QRegExp::CaretMode caretMode = …) const.

C++ documentation:

Attempts to find a match in str from position offset (0 by default). If offset is -1, the search starts at the last character; if -2, at the next to last character; etc.

Returns the position of the first match, or -1 if there was no match.

The caretMode parameter can be used to instruct whether ^ should match at index 0 or at offset.

You might prefer to use QString::indexOf(), QString::contains(), or even QStringList::filter(). To replace matches use QString::replace().

Example:

QString str = “offsets: 1.23 .50 71.00 6.00”; QRegExp rx(“\d*\.\d+”); // primitive floating point matching int count = 0; int pos = 0; while ((pos = rx.indexIn(str, pos)) != -1) { ++count; pos += rx.matchedLength(); } // pos will be 9, 14, 18 and finally 24; count will end up as 4

Although const, this function sets matchedLength(), capturedTexts() and pos().

If the QRegExp is a wildcard expression (see setPatternSyntax()) and want to test a string against the whole wildcard expression, use exactMatch() instead of this function.

See also lastIndexIn() and exactMatch().

source

pub unsafe fn index_in_2a( &self, str: impl CastInto<Ref<QString>>, offset: c_int ) -> c_int

Attempts to find a match in str from position offset (0 by default). If offset is -1, the search starts at the last character; if -2, at the next to last character; etc.

Calls C++ function: int QRegExp::indexIn(const QString& str, int offset = …) const.

C++ documentation:

Attempts to find a match in str from position offset (0 by default). If offset is -1, the search starts at the last character; if -2, at the next to last character; etc.

Returns the position of the first match, or -1 if there was no match.

The caretMode parameter can be used to instruct whether ^ should match at index 0 or at offset.

You might prefer to use QString::indexOf(), QString::contains(), or even QStringList::filter(). To replace matches use QString::replace().

Example:

QString str = “offsets: 1.23 .50 71.00 6.00”; QRegExp rx(“\d*\.\d+”); // primitive floating point matching int count = 0; int pos = 0; while ((pos = rx.indexIn(str, pos)) != -1) { ++count; pos += rx.matchedLength(); } // pos will be 9, 14, 18 and finally 24; count will end up as 4

Although const, this function sets matchedLength(), capturedTexts() and pos().

If the QRegExp is a wildcard expression (see setPatternSyntax()) and want to test a string against the whole wildcard expression, use exactMatch() instead of this function.

See also lastIndexIn() and exactMatch().

source

pub unsafe fn index_in_1a(&self, str: impl CastInto<Ref<QString>>) -> c_int

Attempts to find a match in str from position offset (0 by default). If offset is -1, the search starts at the last character; if -2, at the next to last character; etc.

Calls C++ function: int QRegExp::indexIn(const QString& str) const.

C++ documentation:

Attempts to find a match in str from position offset (0 by default). If offset is -1, the search starts at the last character; if -2, at the next to last character; etc.

Returns the position of the first match, or -1 if there was no match.

The caretMode parameter can be used to instruct whether ^ should match at index 0 or at offset.

You might prefer to use QString::indexOf(), QString::contains(), or even QStringList::filter(). To replace matches use QString::replace().

Example:

QString str = “offsets: 1.23 .50 71.00 6.00”; QRegExp rx(“\d*\.\d+”); // primitive floating point matching int count = 0; int pos = 0; while ((pos = rx.indexIn(str, pos)) != -1) { ++count; pos += rx.matchedLength(); } // pos will be 9, 14, 18 and finally 24; count will end up as 4

Although const, this function sets matchedLength(), capturedTexts() and pos().

If the QRegExp is a wildcard expression (see setPatternSyntax()) and want to test a string against the whole wildcard expression, use exactMatch() instead of this function.

See also lastIndexIn() and exactMatch().

source

pub unsafe fn is_empty(&self) -> bool

Returns true if the pattern string is empty; otherwise returns false.

Calls C++ function: bool QRegExp::isEmpty() const.

C++ documentation:

Returns true if the pattern string is empty; otherwise returns false.

If you call exactMatch() with an empty pattern on an empty string it will return true; otherwise it returns false since it operates over the whole string. If you call indexIn() with an empty pattern on any string it will return the start offset (0 by default) because the empty pattern matches the 'emptiness' at the start of the string. In this case the length of the match returned by matchedLength() will be 0.

See QString::isEmpty().

source

pub unsafe fn is_minimal(&self) -> bool

Returns true if minimal (non-greedy) matching is enabled; otherwise returns false.

Calls C++ function: bool QRegExp::isMinimal() const.

C++ documentation:

Returns true if minimal (non-greedy) matching is enabled; otherwise returns false.

See also caseSensitivity() and setMinimal().

source

pub unsafe fn is_valid(&self) -> bool

Returns true if the regular expression is valid; otherwise returns false. An invalid regular expression never matches.

Calls C++ function: bool QRegExp::isValid() const.

C++ documentation:

Returns true if the regular expression is valid; otherwise returns false. An invalid regular expression never matches.

The pattern [a-z is an example of an invalid pattern, since it lacks a closing square bracket.

Note that the validity of a regexp may also depend on the setting of the wildcard flag, for example *.html is a valid wildcard regexp but an invalid full regexp.

See also errorString().

source

pub unsafe fn last_index_in_3a( &self, str: impl CastInto<Ref<QString>>, offset: c_int, caret_mode: CaretMode ) -> c_int

Attempts to find a match backwards in str from position offset. If offset is -1 (the default), the search starts at the last character; if -2, at the next to last character; etc.

Calls C++ function: int QRegExp::lastIndexIn(const QString& str, int offset = …, QRegExp::CaretMode caretMode = …) const.

C++ documentation:

Attempts to find a match backwards in str from position offset. If offset is -1 (the default), the search starts at the last character; if -2, at the next to last character; etc.

Returns the position of the first match, or -1 if there was no match.

The caretMode parameter can be used to instruct whether ^ should match at index 0 or at offset.

Although const, this function sets matchedLength(), capturedTexts() and pos().

Warning: Searching backwards is much slower than searching forwards.

See also indexIn() and exactMatch().

source

pub unsafe fn last_index_in_2a( &self, str: impl CastInto<Ref<QString>>, offset: c_int ) -> c_int

Attempts to find a match backwards in str from position offset. If offset is -1 (the default), the search starts at the last character; if -2, at the next to last character; etc.

Calls C++ function: int QRegExp::lastIndexIn(const QString& str, int offset = …) const.

C++ documentation:

Attempts to find a match backwards in str from position offset. If offset is -1 (the default), the search starts at the last character; if -2, at the next to last character; etc.

Returns the position of the first match, or -1 if there was no match.

The caretMode parameter can be used to instruct whether ^ should match at index 0 or at offset.

Although const, this function sets matchedLength(), capturedTexts() and pos().

Warning: Searching backwards is much slower than searching forwards.

See also indexIn() and exactMatch().

source

pub unsafe fn last_index_in_1a(&self, str: impl CastInto<Ref<QString>>) -> c_int

Attempts to find a match backwards in str from position offset. If offset is -1 (the default), the search starts at the last character; if -2, at the next to last character; etc.

Calls C++ function: int QRegExp::lastIndexIn(const QString& str) const.

C++ documentation:

Attempts to find a match backwards in str from position offset. If offset is -1 (the default), the search starts at the last character; if -2, at the next to last character; etc.

Returns the position of the first match, or -1 if there was no match.

The caretMode parameter can be used to instruct whether ^ should match at index 0 or at offset.

Although const, this function sets matchedLength(), capturedTexts() and pos().

Warning: Searching backwards is much slower than searching forwards.

See also indexIn() and exactMatch().

source

pub unsafe fn matched_length(&self) -> c_int

Returns the length of the last matched string, or -1 if there was no match.

Calls C++ function: int QRegExp::matchedLength() const.

C++ documentation:

Returns the length of the last matched string, or -1 if there was no match.

See also exactMatch(), indexIn(), and lastIndexIn().

source

pub unsafe fn new_0a() -> CppBox<QRegExp>

Constructs an empty regexp.

Calls C++ function: [constructor] void QRegExp::QRegExp().

C++ documentation:

Constructs an empty regexp.

See also isValid() and errorString().

source

pub unsafe fn new_3a( pattern: impl CastInto<Ref<QString>>, cs: CaseSensitivity, syntax: PatternSyntax ) -> CppBox<QRegExp>

Constructs a regular expression object for the given pattern string. The pattern must be given using wildcard notation if syntax is Wildcard; the default is RegExp. The pattern is case sensitive, unless cs is Qt::CaseInsensitive. Matching is greedy (maximal), but can be changed by calling setMinimal().

Calls C++ function: [constructor] void QRegExp::QRegExp(const QString& pattern, Qt::CaseSensitivity cs = …, QRegExp::PatternSyntax syntax = …).

C++ documentation:

Constructs a regular expression object for the given pattern string. The pattern must be given using wildcard notation if syntax is Wildcard; the default is RegExp. The pattern is case sensitive, unless cs is Qt::CaseInsensitive. Matching is greedy (maximal), but can be changed by calling setMinimal().

See also setPattern(), setCaseSensitivity(), and setPatternSyntax().

source

pub unsafe fn new_2a( pattern: impl CastInto<Ref<QString>>, cs: CaseSensitivity ) -> CppBox<QRegExp>

Constructs a regular expression object for the given pattern string. The pattern must be given using wildcard notation if syntax is Wildcard; the default is RegExp. The pattern is case sensitive, unless cs is Qt::CaseInsensitive. Matching is greedy (maximal), but can be changed by calling setMinimal().

Calls C++ function: [constructor] void QRegExp::QRegExp(const QString& pattern, Qt::CaseSensitivity cs = …).

C++ documentation:

Constructs a regular expression object for the given pattern string. The pattern must be given using wildcard notation if syntax is Wildcard; the default is RegExp. The pattern is case sensitive, unless cs is Qt::CaseInsensitive. Matching is greedy (maximal), but can be changed by calling setMinimal().

See also setPattern(), setCaseSensitivity(), and setPatternSyntax().

source

pub unsafe fn new_1a(pattern: impl CastInto<Ref<QString>>) -> CppBox<QRegExp>

Constructs a regular expression object for the given pattern string. The pattern must be given using wildcard notation if syntax is Wildcard; the default is RegExp. The pattern is case sensitive, unless cs is Qt::CaseInsensitive. Matching is greedy (maximal), but can be changed by calling setMinimal().

Calls C++ function: [constructor] void QRegExp::QRegExp(const QString& pattern).

C++ documentation:

Constructs a regular expression object for the given pattern string. The pattern must be given using wildcard notation if syntax is Wildcard; the default is RegExp. The pattern is case sensitive, unless cs is Qt::CaseInsensitive. Matching is greedy (maximal), but can be changed by calling setMinimal().

See also setPattern(), setCaseSensitivity(), and setPatternSyntax().

source

pub unsafe fn new_copy(rx: impl CastInto<Ref<QRegExp>>) -> CppBox<QRegExp>

Constructs a regular expression as a copy of rx.

Calls C++ function: [constructor] void QRegExp::QRegExp(const QRegExp& rx).

C++ documentation:

Constructs a regular expression as a copy of rx.

See also operator=().

source

pub unsafe fn pattern(&self) -> CppBox<QString>

Returns the pattern string of the regular expression. The pattern has either regular expression syntax or wildcard syntax, depending on patternSyntax().

Calls C++ function: QString QRegExp::pattern() const.

C++ documentation:

Returns the pattern string of the regular expression. The pattern has either regular expression syntax or wildcard syntax, depending on patternSyntax().

See also setPattern(), patternSyntax(), and caseSensitivity().

source

pub unsafe fn pattern_syntax(&self) -> PatternSyntax

Returns the syntax used by the regular expression. The default is QRegExp::RegExp.

Calls C++ function: QRegExp::PatternSyntax QRegExp::patternSyntax() const.

C++ documentation:

Returns the syntax used by the regular expression. The default is QRegExp::RegExp.

See also setPatternSyntax(), pattern(), and caseSensitivity().

source

pub unsafe fn pos_1a(&self, nth: c_int) -> c_int

Returns the position of the nth captured text in the searched string. If nth is 0 (the default), pos() returns the position of the whole match.

Calls C++ function: int QRegExp::pos(int nth = …) const.

C++ documentation:

Returns the position of the nth captured text in the searched string. If nth is 0 (the default), pos() returns the position of the whole match.

Example:

QRegExp rx(“/([a-z]+)/([a-z]+)”); rx.indexIn(“Output /dev/null”); // returns 7 (position of /dev/null) rx.pos(0); // returns 7 (position of /dev/null) rx.pos(1); // returns 8 (position of dev) rx.pos(2); // returns 12 (position of null)

For zero-length matches, pos() always returns -1. (For example, if cap(4) would return an empty string, pos(4) returns -1.) This is a feature of the implementation.

See also cap() and capturedTexts().

source

pub unsafe fn pos_1a_mut(&self, nth: c_int) -> c_int

Returns the position of the nth captured text in the searched string. If nth is 0 (the default), pos() returns the position of the whole match.

Calls C++ function: int QRegExp::pos(int nth = …).

C++ documentation:

Returns the position of the nth captured text in the searched string. If nth is 0 (the default), pos() returns the position of the whole match.

Example:

QRegExp rx(“/([a-z]+)/([a-z]+)”); rx.indexIn(“Output /dev/null”); // returns 7 (position of /dev/null) rx.pos(0); // returns 7 (position of /dev/null) rx.pos(1); // returns 8 (position of dev) rx.pos(2); // returns 12 (position of null)

For zero-length matches, pos() always returns -1. (For example, if cap(4) would return an empty string, pos(4) returns -1.) This is a feature of the implementation.

See also cap() and capturedTexts().

source

pub unsafe fn pos_0a(&self) -> c_int

Returns the position of the nth captured text in the searched string. If nth is 0 (the default), pos() returns the position of the whole match.

Calls C++ function: int QRegExp::pos() const.

C++ documentation:

Returns the position of the nth captured text in the searched string. If nth is 0 (the default), pos() returns the position of the whole match.

Example:

QRegExp rx(“/([a-z]+)/([a-z]+)”); rx.indexIn(“Output /dev/null”); // returns 7 (position of /dev/null) rx.pos(0); // returns 7 (position of /dev/null) rx.pos(1); // returns 8 (position of dev) rx.pos(2); // returns 12 (position of null)

For zero-length matches, pos() always returns -1. (For example, if cap(4) would return an empty string, pos(4) returns -1.) This is a feature of the implementation.

See also cap() and capturedTexts().

source

pub unsafe fn pos_0a_mut(&self) -> c_int

Returns the position of the nth captured text in the searched string. If nth is 0 (the default), pos() returns the position of the whole match.

Calls C++ function: int QRegExp::pos().

C++ documentation:

Returns the position of the nth captured text in the searched string. If nth is 0 (the default), pos() returns the position of the whole match.

Example:

QRegExp rx(“/([a-z]+)/([a-z]+)”); rx.indexIn(“Output /dev/null”); // returns 7 (position of /dev/null) rx.pos(0); // returns 7 (position of /dev/null) rx.pos(1); // returns 8 (position of dev) rx.pos(2); // returns 12 (position of null)

For zero-length matches, pos() always returns -1. (For example, if cap(4) would return an empty string, pos(4) returns -1.) This is a feature of the implementation.

See also cap() and capturedTexts().

source

pub unsafe fn set_case_sensitivity(&self, cs: CaseSensitivity)

Sets case sensitive matching to cs.

Calls C++ function: void QRegExp::setCaseSensitivity(Qt::CaseSensitivity cs).

C++ documentation:

Sets case sensitive matching to cs.

If cs is Qt::CaseSensitive, \.txt$ matches readme.txt but not README.TXT.

See also caseSensitivity(), setPatternSyntax(), setPattern(), and setMinimal().

source

pub unsafe fn set_minimal(&self, minimal: bool)

Enables or disables minimal matching. If minimal is false, matching is greedy (maximal) which is the default.

Calls C++ function: void QRegExp::setMinimal(bool minimal).

C++ documentation:

Enables or disables minimal matching. If minimal is false, matching is greedy (maximal) which is the default.

For example, suppose we have the input string "We must be <b>bold</b>, very <b>bold</b>!" and the pattern <b>.*</b>. With the default greedy (maximal) matching, the match is "We must be <b>bold</b>, very <b>bold</b>!". But with minimal (non-greedy) matching, the first match is: "We must be <b>bold</b>, very <b>bold</b>!" and the second match is "We must be <b>bold</b>, very <b>bold</b>!". In practice we might use the pattern <b>[^<]*</b> instead, although this will still fail for nested tags.

See also isMinimal() and setCaseSensitivity().

source

pub unsafe fn set_pattern(&self, pattern: impl CastInto<Ref<QString>>)

Sets the pattern string to pattern. The case sensitivity, wildcard, and minimal matching options are not changed.

Calls C++ function: void QRegExp::setPattern(const QString& pattern).

C++ documentation:

Sets the pattern string to pattern. The case sensitivity, wildcard, and minimal matching options are not changed.

See also pattern(), setPatternSyntax(), and setCaseSensitivity().

source

pub unsafe fn set_pattern_syntax(&self, syntax: PatternSyntax)

Sets the syntax mode for the regular expression. The default is QRegExp::RegExp.

Calls C++ function: void QRegExp::setPatternSyntax(QRegExp::PatternSyntax syntax).

C++ documentation:

Sets the syntax mode for the regular expression. The default is QRegExp::RegExp.

Setting syntax to QRegExp::Wildcard enables simple shell-like QRegExp wildcard matching. For example, r*.txt matches the string readme.txt in wildcard mode, but does not match readme.

Setting syntax to QRegExp::FixedString means that the pattern is interpreted as a plain string. Special characters (e.g., backslash) don't need to be escaped then.

See also patternSyntax(), setPattern(), setCaseSensitivity(), and escape().

source

pub unsafe fn swap(&self, other: impl CastInto<Ref<QRegExp>>)

Swaps regular expression other with this regular expression. This operation is very fast and never fails.

Calls C++ function: void QRegExp::swap(QRegExp& other).

C++ documentation:

Swaps regular expression other with this regular expression. This operation is very fast and never fails.

This function was introduced in Qt 4.8.

Trait Implementations§

source§

impl CppDeletable for QRegExp

source§

unsafe fn delete(&self)

Destroys the regular expression and cleans up its internal data.

Calls C++ function: [destructor] void QRegExp::~QRegExp().

C++ documentation:

Destroys the regular expression and cleans up its internal data.

source§

impl PartialEq<Ref<QRegExp>> for QRegExp

source§

fn eq(&self, rx: &Ref<QRegExp>) -> bool

Returns true if this regular expression is equal to rx; otherwise returns false.

Calls C++ function: bool QRegExp::operator==(const QRegExp& rx) const.

C++ documentation:

Returns true if this regular expression is equal to rx; otherwise returns false.

Two QRegExp objects are equal if they have the same pattern strings and the same settings for case sensitivity, wildcard and minimal matching.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.