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

Regex pattern for CORS origin domain

The CORS origin spec requires the origin to be of the following possibilities: Origin: :// Origin: ://: I would like to have a regex that can match origins with the above criteria; sample domains to…
L P
  • 1,776
  • 5
  • 25
  • 46
1
vote
1 answer

Which standard of regular expressions does Qt use?

I use https://regex101.com and https://www.regextester.com to check my regular expressions. I presume Qt uses PCRE or PCRE2, but sometimes it won't work as expected. This makes me think that Qt uses some other version of regex standard. Which is…
Mykola Tetiuk
  • 157
  • 3
  • 9
1
vote
1 answer

Combine two RegEx?

I need to create a regular expression which transforms a path to a cloud solution. \\test.local\testb\test-prozesse\project_prozess\1_Implementierung\2__Datenmigration\1_prozesstest\5_Dokumentation\Dateiname.docx to…
LaYn
  • 11
  • 2
1
vote
1 answer

RegEx to accept String, # and a number

I am trying to add the commit message hook to accept the following inputs in Gitlab: bug 12345 bug #12345 BUG # 12345 Bug#12345 bug12345 The number 12345 should be changed to anything which is either a 5 digit or 6 digit number (not less than that,…
Sameer Atharkar
  • 382
  • 1
  • 3
  • 17
1
vote
2 answers

How to split decimal numbers followed by letters?

I have date like the following A <- c("-0.00023--0.00243unitincrease", "-0.00176-0.02176pmol/Lincrease(replication)", "0.00180-0.01780%varianceunitdecrease") I want to extract the digits part and the rest part as two columns B and C. after…
Zhoufeng
  • 25
  • 5
1
vote
3 answers

Match an expression but don't match lines that start with a #

I am us Qt. I have a text string that I specifically look for a function call xyz.set_name(), I want to capture the last occurrence of this call but negate it if the line that contains it starts with a #. So far I got the regex to match the function…
reddy
  • 1,721
  • 3
  • 16
  • 26
1
vote
1 answer

How to find a long double number in a string in java

I am trying to extract the end to end delay value which is exist in each line in a text file. I used regular expression to get only the number at the end of each line, but i got error for the regular expression which is: illegal escape…
1
vote
1 answer

QRegularExpression to find numeric part of file name

I have the entire path of a file available in a Qstring Qstring str = "d://output/File_012_xyz/logs"; From this I wanted to extract the number 12. I tried something like this QRegularExpression rx("[1-9]+"); QRegularExpressionMatchIterator i =…
sn710
  • 581
  • 5
  • 20
1
vote
1 answer

QStringList does not return index by QRegularExpression

What am I doing wrong? I want to find an index of a string, which matches given QRegularExpression, in QStringList. #include #include #include #include int main(int argc, char…
Alex Chudinov
  • 654
  • 1
  • 6
  • 12
1
vote
0 answers

QTextEdit not highlighting simple two lines. I am using QRegularExpression for Qt 5.13 MinGw x64

I have the simplest minimum working example to highlight just two lines. The two lines to be highlighted are shown below. These two lines are the only contents of the QTextEdit. begin end Using QSyntaxHighlighter and QTextEdit, I am unable to…
rasi
  • 11
  • 2
1
vote
1 answer

Extract strings inside double quotes with QRegularExpression

I have a string like below: on prepareFrame go to frame 10 goToNetPage "http://www.apple.com" goToNetPage "http://www.cnn.com" etc.. end I want to extract all the urls from this string by using QRegularExpression. I've already…
Mosi
  • 1,178
  • 2
  • 12
  • 30
1
vote
0 answers

How do I use multi-line patterns with QRegularExpression?

Qt 5.12.0 I'm using a class derived from QSyntaxHighlighter to highlight text in a QTextEdit widget. I've overridden the highlightBlock(const QString & text) function and I'm trying to make a multi-line regex pattern using…
tguen
  • 189
  • 1
  • 9
1
vote
1 answer

How to remove the first character if it's a comma using QRegExp?

I have the following QRegExpValidator QRegExpValidator doubleValidator = new QRegExpValidator(QRegExp("[-+]?[0-9]*[\\.,]?[0-9]+([eE][-+]?[0-9]+)?")); It's supposed to be a Double numbers validator that accepts numbers, only one "e" sign, one comma…
1
vote
2 answers

Regular expression for match string with new line char

How use regular expression to match in text passphrase between Passphrase= string and \n char (Select: testpasssword)? The password can contain any characters. My partial solution: Passphrase.*(?=\\nName) =>…
kluszon
  • 375
  • 5
  • 19
1
vote
1 answer

qt regular expression look behind

my regular expression :(?<=defining\s)[^;]* should try to find var in the following cases: defining var; some text defining var; I tested the regular expression using some online tools. Unfortunately it does not work with Qt for some reason. Is…
user7431005
  • 3,899
  • 4
  • 22
  • 49