#[repr(C)]pub struct QRegExp { /* private fields */ }
Expand description
The QRegExp class provides pattern matching using regular expressions.
C++ class: 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 mail, letter or correspondence, but none of the words email, mailman, mailer, letterbox, 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 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
impl QRegExp
sourcepub unsafe fn cap_1a(&self, nth: c_int) -> CppBox<QString>
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
.
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().
sourcepub unsafe fn cap_1a_mut(&self, nth: c_int) -> CppBox<QString>
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 = …)
.
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().
sourcepub unsafe fn cap_0a(&self) -> CppBox<QString>
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
.
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().
sourcepub unsafe fn cap_0a_mut(&self) -> CppBox<QString>
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()
.
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().
sourcepub unsafe fn capture_count(&self) -> c_int
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
.
Returns the number of captures contained in the regular expression.
This function was introduced in Qt 4.6.
sourcepub unsafe fn captured_texts(&self) -> CppBox<QStringList>
pub unsafe fn captured_texts(&self) -> CppBox<QStringList>
Returns a list of the captured text strings.
Calls C++ function: QStringList QRegExp::capturedTexts() const
.
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).
sourcepub unsafe fn captured_texts_mut(&self) -> CppBox<QStringList>
pub unsafe fn captured_texts_mut(&self) -> CppBox<QStringList>
Returns a list of the captured text strings.
Calls C++ function: QStringList QRegExp::capturedTexts()
.
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).
sourcepub unsafe fn case_sensitivity(&self) -> CaseSensitivity
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
.
Returns Qt::CaseSensitive if the regexp is matched case sensitively; otherwise returns Qt::CaseInsensitive.
See also setCaseSensitivity(), patternSyntax(), pattern(), and isMinimal().
sourcepub unsafe fn copy_from(&self, rx: impl CastInto<Ref<QRegExp>>) -> Ref<QRegExp>
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)
.
Copies the regular expression rx and returns a reference to the copy. The case sensitivity, wildcard, and minimal matching options are also copied.
sourcepub unsafe fn error_string(&self) -> CppBox<QString>
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
.
Returns a text string that explains why a regexp pattern is invalid the case being; otherwise returns “no error occurred”.
See also isValid().
sourcepub unsafe fn error_string_mut(&self) -> CppBox<QString>
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()
.
Returns a text string that explains why a regexp pattern is invalid the case being; otherwise returns “no error occurred”.
See also isValid().
sourcepub unsafe fn escape(str: impl CastInto<Ref<QString>>) -> CppBox<QString>
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)
.
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().
sourcepub unsafe fn exact_match(&self, str: impl CastInto<Ref<QString>>) -> bool
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
.
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().
sourcepub unsafe fn index_in_3a(
&self,
str: impl CastInto<Ref<QString>>,
offset: c_int,
caret_mode: CaretMode
) -> c_int
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
.
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().
sourcepub unsafe fn index_in_2a(
&self,
str: impl CastInto<Ref<QString>>,
offset: c_int
) -> c_int
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
.
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().
sourcepub unsafe fn index_in_1a(&self, str: impl CastInto<Ref<QString>>) -> c_int
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
.
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().
sourcepub unsafe fn is_empty(&self) -> bool
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
.
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().
sourcepub unsafe fn is_minimal(&self) -> bool
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
.
Returns true
if minimal (non-greedy) matching is enabled; otherwise returns false
.
See also caseSensitivity() and setMinimal().
sourcepub unsafe fn is_valid(&self) -> bool
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
.
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().
sourcepub unsafe fn last_index_in_3a(
&self,
str: impl CastInto<Ref<QString>>,
offset: c_int,
caret_mode: CaretMode
) -> c_int
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
.
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().
sourcepub unsafe fn last_index_in_2a(
&self,
str: impl CastInto<Ref<QString>>,
offset: c_int
) -> c_int
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
.
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().
sourcepub unsafe fn last_index_in_1a(&self, str: impl CastInto<Ref<QString>>) -> c_int
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
.
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().
sourcepub unsafe fn matched_length(&self) -> c_int
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
.
Returns the length of the last matched string, or -1 if there was no match.
See also exactMatch(), indexIn(), and lastIndexIn().
sourcepub unsafe fn new_0a() -> CppBox<QRegExp>
pub unsafe fn new_0a() -> CppBox<QRegExp>
Constructs an empty regexp.
Calls C++ function: [constructor] void QRegExp::QRegExp()
.
Constructs an empty regexp.
See also isValid() and errorString().
sourcepub unsafe fn new_3a(
pattern: impl CastInto<Ref<QString>>,
cs: CaseSensitivity,
syntax: PatternSyntax
) -> CppBox<QRegExp>
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 = …)
.
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().
sourcepub unsafe fn new_2a(
pattern: impl CastInto<Ref<QString>>,
cs: CaseSensitivity
) -> CppBox<QRegExp>
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 = …)
.
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().
sourcepub unsafe fn new_1a(pattern: impl CastInto<Ref<QString>>) -> CppBox<QRegExp>
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)
.
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().
sourcepub unsafe fn new_copy(rx: impl CastInto<Ref<QRegExp>>) -> CppBox<QRegExp>
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)
.
Constructs a regular expression as a copy of rx.
See also operator=().
sourcepub unsafe fn pattern(&self) -> CppBox<QString>
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
.
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().
sourcepub unsafe fn pattern_syntax(&self) -> PatternSyntax
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
.
Returns the syntax used by the regular expression. The default is QRegExp::RegExp.
See also setPatternSyntax(), pattern(), and caseSensitivity().
sourcepub unsafe fn pos_1a(&self, nth: c_int) -> c_int
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
.
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().
sourcepub unsafe fn pos_1a_mut(&self, nth: c_int) -> c_int
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 = …)
.
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().
sourcepub unsafe fn pos_0a(&self) -> c_int
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
.
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().
sourcepub unsafe fn pos_0a_mut(&self) -> c_int
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()
.
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().
sourcepub unsafe fn set_case_sensitivity(&self, cs: CaseSensitivity)
pub unsafe fn set_case_sensitivity(&self, cs: CaseSensitivity)
Sets case sensitive matching to cs.
Calls C++ function: void QRegExp::setCaseSensitivity(Qt::CaseSensitivity cs)
.
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().
sourcepub unsafe fn set_minimal(&self, minimal: bool)
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)
.
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().
sourcepub unsafe fn set_pattern(&self, pattern: impl CastInto<Ref<QString>>)
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)
.
Sets the pattern string to pattern. The case sensitivity, wildcard, and minimal matching options are not changed.
See also pattern(), setPatternSyntax(), and setCaseSensitivity().
sourcepub unsafe fn set_pattern_syntax(&self, syntax: PatternSyntax)
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)
.
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().
sourcepub unsafe fn swap(&self, other: impl CastInto<Ref<QRegExp>>)
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)
.
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
impl CppDeletable for QRegExp
source§impl PartialEq<Ref<QRegExp>> for QRegExp
impl PartialEq<Ref<QRegExp>> for QRegExp
source§fn eq(&self, rx: &Ref<QRegExp>) -> bool
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
.
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.