Skip to content

PythonQt.QtCore.QRegExp · declarations 001

Back to PythonQt.QtCore.QRegExp

CaretAtOffset instance-attribute

CaretAtOffset: Any

CaretAtZero instance-attribute

CaretAtZero: Any

CaretMode instance-attribute

CaretMode: type

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.

int('0b100', base=0) 4

CaretWontMatch instance-attribute

CaretWontMatch: Any

FixedString instance-attribute

FixedString: Any

PatternSyntax instance-attribute

PatternSyntax: type

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.

int('0b100', base=0) 4

RegExp instance-attribute

RegExp: Any

RegExp2 instance-attribute

RegExp2: Any

W3CXmlSchema11 instance-attribute

W3CXmlSchema11: Any

Wildcard instance-attribute

Wildcard: Any

WildcardUnix instance-attribute

WildcardUnix: Any

cap

cap(nth: int) -> str

X.cap(nth) -> str

Supplemental documentation: Qt 5 reference:

QString QRegExp::cap(int nth \= 0) 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().

Upstream PySide2 reference signatures (binding differences may apply):

cap(self, nth: int=...) -> str

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#cap

captureCount

captureCount() -> int

X.captureCount() -> int

Supplemental documentation: Qt 5 reference:

int QRegExp::captureCount() const

Returns the number of captures contained in the regular expression.

This function was introduced in Qt 4.6.

Upstream PySide2 reference signatures (binding differences may apply):

captureCount(self) -> int

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#captureCount

capturedTexts

capturedTexts() -> tuple

X.capturedTexts() -> tuple

Supplemental documentation: Qt 5 reference:

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

See also cap() and pos().

Upstream PySide2 reference signatures (binding differences may apply):

capturedTexts(self) -> typing.List[str]

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#capturedTexts

caseSensitivity

caseSensitivity() -> Any

X.caseSensitivity()

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

caseSensitivity(self) -> PySide2.QtCore.Qt.CaseSensitivity

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#caseSensitivity

errorString

errorString() -> str

X.errorString() -> str

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

errorString(self) -> str

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#errorString

escape

escape(str: str) -> str

X.escape(str) -> str

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

escape(str: str) -> str

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#escape

exactMatch

exactMatch(str: str) -> bool

X.exactMatch(str) -> bool

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

exactMatch(self, str: str) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#exactMatch

indexIn

indexIn(str: str, offset: int, caretMode: Any) -> int

X.indexIn(str, offset, caretMode) -> int

Supplemental documentation: Qt 5 reference:

int QRegExp::indexIn(const QString \&str, int offset \= 0, QRegExp::CaretMode caretMode \= CaretAtZero) 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().

Upstream PySide2 reference signatures (binding differences may apply):

indexIn(self, str: str, offset: int=..., caretMode: PySide2.QtCore.QRegExp.CaretMode=...) -> int

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#indexIn

isEmpty

isEmpty() -> bool

X.isEmpty() -> bool

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

isEmpty(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#isEmpty

isMinimal

isMinimal() -> bool

X.isMinimal() -> bool

Supplemental documentation: Qt 5 reference:

bool QRegExp::isMinimal() const

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

See also caseSensitivity() and setMinimal().

Upstream PySide2 reference signatures (binding differences may apply):

isMinimal(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#isMinimal

isValid

isValid() -> bool

X.isValid() -> bool

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

isValid(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#isValid

lastIndexIn

lastIndexIn(str: str, offset: int, caretMode: Any) -> int

X.lastIndexIn(str, offset, caretMode) -> int

Supplemental documentation: Qt 5 reference:

int QRegExp::lastIndexIn(const QString \&str, int offset \= -1, QRegExp::CaretMode caretMode \= CaretAtZero) 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().

Upstream PySide2 reference signatures (binding differences may apply):

lastIndexIn(self, str: str, offset: int=..., caretMode: PySide2.QtCore.QRegExp.CaretMode=...) -> int

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#lastIndexIn

matchedLength

matchedLength() -> int

X.matchedLength() -> int

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

matchedLength(self) -> int

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#matchedLength

pattern

pattern() -> str

X.pattern() -> str

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

pattern(self) -> str

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#pattern

patternSyntax

patternSyntax() -> Any

X.patternSyntax()

Supplemental documentation: Qt 5 reference:

QRegExp::PatternSyntax QRegExp::patternSyntax() const

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

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

Upstream PySide2 reference signatures (binding differences may apply):

patternSyntax(self) -> PySide2.QtCore.QRegExp.PatternSyntax

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#patternSyntax

pos

pos(nth: int) -> int

X.pos(nth) -> int

Supplemental documentation: Qt 5 reference:

int QRegExp::pos(int nth \= 0) 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().

Upstream PySide2 reference signatures (binding differences may apply):

pos(self, nth: int=...) -> int

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#pos

readFrom

readFrom(*args: Any, **kwargs: Any) -> Any

X.readFrom(in)

setCaseSensitivity

setCaseSensitivity(cs: Any) -> None

X.setCaseSensitivity(cs)

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

setCaseSensitivity(self, cs: PySide2.QtCore.Qt.CaseSensitivity) -> None

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#setCaseSensitivity

setMinimal

setMinimal(minimal: bool) -> None

X.setMinimal(minimal)

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

setMinimal(self, minimal: bool) -> None

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#setMinimal

setPattern

setPattern(pattern: str) -> None

X.setPattern(pattern)

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

setPattern(self, pattern: str) -> None

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#setPattern

setPatternSyntax

setPatternSyntax(syntax: Any) -> None

X.setPatternSyntax(syntax)

Supplemental documentation: Qt 5 reference:

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

Upstream PySide2 reference signatures (binding differences may apply):

setPatternSyntax(self, syntax: PySide2.QtCore.QRegExp.PatternSyntax) -> None

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#setPatternSyntax

swap

swap(other: Any) -> None

X.swap(other)

Supplemental documentation: Qt 5 reference:

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.

Upstream PySide2 reference signatures (binding differences may apply):

swap(self, other: PySide2.QtCore.QRegExp) -> None

Source: https://doc.qt.io/archives/qt-5.15/qregexp.html#swap

writeTo

writeTo(out: Any) -> Any

X.writeTo(out)