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
8
votes
1 answer

How to get substring from a string in qt?

I have a text form: Last Name:SomeName, Day:23 ...etc From Last Name:SomeName, I would like to get Last Name, and separately SomeName. I have tried to use QRegularExpression, QRegularExpression re("(?
amol01
  • 1,823
  • 4
  • 21
  • 35
7
votes
1 answer

In Qt, what takes the least amount of code to replace string matches with regular expression captures?

I was hoping that QString would allow this: QString myString("School is LameCoolLame and LameRadLame"); myString.replace(QRegularExpression("Lame(.+?)Lame"),"\1"); Leaving "School is Cool and Rad" Instead from what I saw in the docs, doing this is…
Anon
  • 2,267
  • 3
  • 34
  • 51
4
votes
1 answer

Does QRegularExpression remove Backreferences (and faster searching as a result)

A cursory look at the documentation for QRegexp shows that it supports backreferences, while QRegularExpression makes no mention of it. This would be notable since regular expression matching without backreferences can scale in linear time, while…
Alex Huszagh
  • 13,272
  • 3
  • 39
  • 67
3
votes
2 answers

Case insensitive search mode with QRegularExpression

This question is an expanded question of this : How to replace QRegExp in a string? In that question, problem is solved. But now I need to use QRegularExpression instead of QRegExp. How should I transfer the answer of Toby Speight?
songvan
  • 369
  • 5
  • 21
3
votes
6 answers

How to count recurring characters at the beginning of a QString?

Im dealing with a list of lines, and I need to count the hashes that occur at the beginning. # item 1 ## item 1, 1 ## item 1, 2 # item 2 and so on. If each line is a QString, how can I return the number of hashes occurring at the beginning of the…
Anon
  • 2,267
  • 3
  • 34
  • 51
3
votes
2 answers

QT application with QList function "append"

I'm trying to return a list of matches returned from a QRegularExpression to a QList with this code below: QList list(); QString str ("something by the way"); QRegularExpression reA("pattern"); QRegularExpressionMatchIterator i =…
Jorge Luis
  • 902
  • 12
  • 25
3
votes
2 answers

Qt QLineEdit Input Validation

How would one set an input validator on a QLineEdit such that it restricts it to a valid IP address? i.e. x.x.x.x where x must be between 0 and 255.and x can not be empty
3
votes
1 answer

Regular Expression in Qt

I am using Qt5.6. I need to process the incoming data in a serial port, the data will be of the format "AD=+172345AD=+272345" and so on. I append the incoming data to a QString and using Regex to extract the decimals. If I write a regular expression…
Sivaram
  • 155
  • 1
  • 8
3
votes
1 answer

Match any char inside two quotation pairs, including nested quotations

I have data that will appear as dual quotation pairs like this, per line. "Key" "Value" Inside of these pairs there can be any character, and sometimes there comes the dreaded "" nested pair: "Key "superkey"" ""Space" Value" Previously I've…
CZauX
  • 109
  • 2
  • 9
3
votes
3 answers

Qt Using QRegularExpression multiline option

I'm writing a program that use QRegularExpression and MultilineOption, I wrote this code but matching stop on first line. Why? Where am I doing wrong? QString recv =…
PeterBlack
  • 33
  • 1
  • 3
2
votes
2 answers

How not to create temporary QRegularExpression objects

I am getting this warning in Qt Creator: Don't create temporary QRegularExpression objects. Use a static QRegularExpression object instead [clazy-use-static-qregularexpression] And it's regarding the code snippet below: QRegularExpression…
TSG
  • 4,242
  • 9
  • 61
  • 121
2
votes
1 answer

why precedence over disjunction

I have a question about operator precedence hierarchy, why "Because sequences have a higher precedence than disjunction, /the|any/ matches the or any but not thany or they"? I just couldn't understand why this result reflects "precedence over…
Wei Ren
  • 23
  • 2
2
votes
1 answer

Regular expression to disallow empty string and comma

I'm trying to write regular expression to restrict empty string and comma inside a string example: string = "" # not allowed s = "ab c!@#)(*&^%$#~" # allowed s = "sfsfsf,sdfsdf" # not allowed The intention of this regexp is to do a pattern matching…
2
votes
1 answer

PyQt5: how to do replacement using QRegularExpression

I want to reserve all English characters and replace others. When using 're' module, it looks like that: name = 'srw 959we' result = sub('/W', '', name) Then I get name = 'srwwe'. Now I want to use the class QRegularExpression to realize that, but…
ham
  • 23
  • 4
2
votes
1 answer

How to find a word that starts with a special letter and end with a special letter in SQL, Regular Expression/REGEX

I try to learn SQL and Regex at the moment to analyse data in google data studio. I tried to find a solution to my problem but I could not find any online. I have a data source with search queries and I want to tag all queries which are including…
Yannik
  • 21
  • 1
1
2 3 4 5 6 7 8