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
0
votes
2 answers

Regular Expression Filter for QFileDialog

I would like to display a file open dialog that filters on a particular pattern, for example *.000 to *.999. QFileDialog::getOpenFileNames allows you to specify discrete filters, such as *.000, *.001, etc. I would like to set a regular expression as…
Jamerson
  • 474
  • 3
  • 14
0
votes
1 answer

Restrict a character in a series of characters in Regexp

In the below example I have a series a characters within the [] which the users are allowed to enter. In this, I want a particular character to be restricted to, say, once. For example, I want the user to enter the . only once. Now, I tried…
jxgn
  • 741
  • 2
  • 15
  • 36
0
votes
1 answer

QRegExp for IP Address of QlineEDit in QT

How we can validate for QlineEdit control when i want to enter the IP Address into QlineEdit control, that control should be allow only IP address . don't allow any alphabets ,characters except dot(.) All the parts should be in range of 0-255 IP…
Rishabh Bansal
  • 51
  • 1
  • 1
  • 9
0
votes
2 answers

How to get this regular expression

I have this piece of code: Memorial do Convento - Texto em Análise ...and I want to get this part: Memorial do Convento - Texto em Análise How…
0
votes
2 answers

Qt / QRegularExpression - Can't capture all results, only 1st instance, why?

I am trying to get some text surrounded by tags. My problem is that I am able to fetch the first result only, and can't get others. From the following HTML, I only get the 1st result which is this text: Student Name But all other attempts to…
Alaa Salah
  • 885
  • 1
  • 13
  • 23
0
votes
1 answer

What is a proper way to remove certain HTML Tags or Brackets containing text in a QString using the Qt Library?

I have a lot of unstandardised HTML (Mixed in with a bunch of Wiki markup) in which I need to strip certain tags and various brackets from it. QRegularExpression is not the right tool for the job, as a simple string here demonstrates: myString…
Anon
  • 2,267
  • 3
  • 34
  • 51
0
votes
1 answer

QString::split(const QRegularExpression) issue

My app downloads a HTML webpage source code and then try to exctract html lines (tr). My code: QStringList linesPage1 = page1.split(QRegularExpression("")); But when I do this: qDebug() << linesPage1; I got this: ("
ceriums
  • 83
  • 1
  • 1
  • 7
0
votes
1 answer

The regular expression won't work on Qt5.5

I want to split the string into substrings wherever blank lines occurs; the content like this: aa aa bb bb cc cc I want to get a List like this : List["aa aa", "bb bb", "cc cc"]; code : QRegularExpression re("^(\\s*)\\n"); //or…
Shennorth
  • 31
  • 2
0
votes
2 answers

QRegularExpression For Phone Number

I am trying to use regular expressions to validate phone numbers but its just allowing all numbers to be accepted not just 10, my regular expression is ^[0-9]{10} which should just allow 10 numbers 0-9. my test strings were 1234567890 which passed…
Root0x
  • 472
  • 1
  • 9
  • 28
0
votes
1 answer

How to find two digit number that is not part of a date using regular expression

I have this long string value: "10 12 10/05/2014 p4=34" I would like to get only the two digit numbers (underlined): "10 12 10/05/2014 p4=34" -- -- -- So the result should be 10 12 34
MRK
  • 63
  • 4
0
votes
1 answer

QRegularExpression Lineedit Validatoin

Hello i'm trying to validate the data (consisting of names of 2 or more words) from a lineedit widget using regular expressions in qt the issue is that qt is allowing anything in the lineedit widget my code is below, thank you. QRegularExpression…
Root0x
  • 113
  • 1
  • 2
  • 12
0
votes
0 answers

Segmentation fault when Initializing QRegularExpression, but only sometimes

this is one of my strangest errors. QRegularExpression regexp(" .*"); This works fine, sometimes. But than it crashes with segmentation faul. 0 _int_malloc /usr/lib64/libc.so.6 0x7ffff59f2196 1 malloc /usr/lib64/libc.so.6 …
J.W.
  • 81
  • 10
0
votes
2 answers

QRegularExpression - How to extract string from between two tags?

I am trying to get the text within multiple tags as following: Text File: Internal Auto-Configured Settings File ________________________________________ (( Do not attempt to edit it manually )) ________________________________________ # Saved…
Alaa Salah
  • 885
  • 1
  • 13
  • 23
-1
votes
1 answer

Regular expressions postgresql

I need your help, I am a new user in postgresSQL. I only have the first column, need to get the second one like this--> Column A Column…
Alex
  • 1
  • 2
-1
votes
1 answer

QRegularExpression: how to get the failing position?

I guess that this has had to be asked before, but cannot find anything about it. I also think that maybe the answer is just right there but I can't see it either. So, if QRegularExpression::match() has not a match, how do I know the position of the…
Alvein
  • 167
  • 1
  • 9