Questions tagged [qregularexpression]

The QRegularExpression class in Qt 5 and 6 provides pattern matching using regular expressions. This tag is for questions about the use of regular expressions in the Qt library. For generic questions about regular expressions, use the "regex" tag.

The QRegularExpression class provides pattern matching using regular expressions in the Qt framework.

The regular expression syntax in QRegularExpression is modeled after Perl (PCRE).

Note: This class is new in Qt 5. Qt also offers an older, slightly less capable regex implementation though the QRegExp class.

Usage example for finding all numbers in a string:

QRegularExpression re("(\\d+)");
QString str = "Offsets: 12 14 99 231 7";
QStringList list;
QRegularExpressionMatchIterator i = re.globalMatch(str);

while (i.hasNext()) {
    QRegularExpressionMatch match = i.next();
    list << match.captured(1);
}
// list: ["12", "14", "99", "231", "7"]

Read on in the official Qt documentation for Qt 5.

120 questions
1
vote
2 answers

QT regularExpressions retrieve numbers

I've to split simple QStrings of the form "number number number",for example " 2323 432 1223". The code i use is QString line; QRegularExpression re("(\\d+)"); QRegularExpressionMatch match; while(!qtextstream.atEnd()){ line =…
1
vote
2 answers

QRegularExpression: skip matching escaped tokens

I'm replacing a QString using QRegularExpression but I have a problem with escaped tokens. For example: a "{aaa}" in the string should be replace with a "bbb" but a "\{aaa}" should be ignored and a "{aaa}" will be set (without the "\"). eg: this is…
marco
  • 1,686
  • 1
  • 25
  • 33
1
vote
1 answer

QRegularExpression escape Asterisk as Character

I'm trying to match strings which look either like this: 7;7;52*8 8;8;62*5 9;9;55*1 11;7;52*49 12;8;62*64 14;9;54*62 or like this: 7;7;52 8;8;62 9;9;55 11;7;52 12;8;62 14;9;54 I'm using the following…
momor10
  • 478
  • 3
  • 11
1
vote
1 answer

how do I use QRegularExpression in Qt

I searched (an incredible amount of time) through Qt Documentation and some other documentation online but I can't get an answer. I'm using a QLineEdit which will take a "C++ class name" (that means it should accept only [a-b](<-uppercase as well),…
Nhatz HK
  • 42
  • 2
  • 11
1
vote
1 answer

QRegExp getting Duplication in Debug Result

My Code is : QString strExp="Sum(2+3)-Sum(5+3)"; QRegExp regexp("(Sum\\([^)]*\\))"); regexp.indexIn(strExp); QStringList lst=regexp.capturedTexts(); qDebug()<<"CapturedCounts:"<
1
vote
1 answer

Extract a decimal number from a sentence using a QRegularExpression

I am currently trying to extract the following decimal number: 2453.6756667756 from the following sentence: ID: 1 x: 1202 y: 2453.6756667756 w: 242 I am using this code: regularExpression.setPattern("(\\d+)(?:\\s*)(w:)") However it gives me…
Dave_Dev
  • 303
  • 1
  • 12
1
vote
1 answer

Avoid the \r when applying a QRegularExpression to a sentence

I have extracted the following sentence : Very important point. It should be discussed in our next meeting. from the following line: ID: 1 x: 1202 y: 2453 w: 242 h: 459 wn: 13 ln: 12 c: Very important point. It should be discussed in our next…
Dave_Dev
  • 303
  • 1
  • 12
1
vote
1 answer

terminating filters in a list using RegEx

Our site has more than 20K pages, each with a distinct ID in the URL that allows us to identify who was visited. We want to run a comparison. However, using regular expression, I cannot narrow my filter to a specific list of sites, because the…
1
vote
2 answers

QRegularExpression - find match with captured length backwards

I can find previous match with this, but what I can't do, is to capture the length of the matched string: int pos = 0; if((pos = text.lastIndexOf(QRegularExpression(pattern), cursorPosition - 1)) != -1)) cout << "Match at position: " << pos <<…
LogicStuff
  • 19,397
  • 6
  • 54
  • 74
1
vote
1 answer

QLineEdit with no decimal point

I want the QLineEdit to accept only numbers without any decimal.e.g it should accept '456' but not '456.3434'.i.e. it should not allow decimal at all. Can anybody give some pointers that how can i do that. I tried to use QIntValidator, but it still…
user1703942
  • 317
  • 3
  • 15
1
vote
1 answer

Error while building Qt 5.3

When I want to build Qt 5.3 on Windows, it give me an error: mingw32-make[4]: Entering directory 'c:/qt-5.3.0/qtbase/src/corelib' g++ -c -include .pch\release\qt_pch.h -pipe -fno-keep-inline-dllexport -O2 -std= gnu++0x -fexceptions -mthreads -frtti…
gcdu97
  • 25
  • 8
0
votes
0 answers

Escaping characters before converting a wildcard pattern to a regular expression

The user provides a search string, and this string is dynamically converted to a regex, because the subsequent search code doesn't take a plain string but a regex as input. I want the characters * and ? to have special meanings in this user-provided…
Gras Double
  • 15,901
  • 8
  • 56
  • 54
0
votes
1 answer

setMinimal equivalent in QRegularExpression

I am porting some Qt5 code to Qt6, which requires switching QRegExp to QRegularExpression. The Qt5 code uses the setMinimal(bool minimal) method of QRegExp. Is there an equivalent PatternOption in Qt6? I see a…
TSG
  • 4,242
  • 9
  • 61
  • 121
0
votes
0 answers

Escape asterisk inside QRegularExpression character class

I have a regular expression that worked with QRegExp, but is considered invalid by QRegularExpression: \[[a-zA-Z0-9/^-*]+\] In most regular expression systems I've come across, the asterisk has no special meaning inside a character class, but here…
Michael Clerx
  • 2,928
  • 2
  • 33
  • 47
0
votes
0 answers

QString.split missing some empty lines

I'm stuck with this. I am trying to tokenize a multiline QString and count the number of lines. QStringList sentences = m_text.split(QRegularExpression("\n|$"), Qt::SkipEmptyParts); qDebug() << sentences.size(); In spite of the Qt::SkipEmptyParts…
coterobarros
  • 941
  • 1
  • 16
  • 25