Questions tagged [qregexp]

QRegExp is a Qt class that provides the functionality of regular expressions.

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

The default regular expression syntax in QRegExp is modeled after Perl (PCRE), but it supports some other syntaxes as well.

Note: Qt 5+ offers a more modern regex implementation though the QRegularExpression class.

Usage example for finding all numbers in a string:

QRegExp rx("(\\d+)");
QString str = "Offsets: 12 14 99 231 7";
QStringList list;
int pos = 0;

while ((pos = rx.indexIn(str, pos)) != -1) {
    list << rx.cap(1);
    pos += rx.matchedLength();
}
// list: ["12", "14", "99", "231", "7"]

Read on in the official Qt documentation for Qt 4.8 and for Qt 5.

181 questions
0
votes
2 answers

How to get the src of an image tag using QRegExp and QString

So I have got a string in my app which contains an html img tag Now I want to extract the image tag and its src attribute in two different strings. So what I tried to do is this: QRegExp…
reckless
  • 741
  • 12
  • 53
0
votes
0 answers

QRegExp format for finding the strings which contains one new line character '\n' and arbitrary count spaces ' '

How to write QRegExp pattern for finding the strings which contains one new line character '\n' and arbitrary count spaces ' '?
ma13
  • 53
  • 1
  • 9
0
votes
1 answer

QRegExp over multiple lines with quotation marks

I want to match the first and last quotation mark from the example code below using QRegExp: echo "#!/bin/bash VAR="Test" Script content " > $SCRIPT I have tested several different expressions, the closest I have gotten so far is by using…
eivindmu
  • 1
  • 2
0
votes
2 answers

QRegExp and colon after string

I have a problem with QRegExp. This is my source. I would like both the "Re:" and "Fwd:" substrings to be deleted: #include "mainwindow.h" #include "ui_mainwindow.h" #include #include using namespace…
felice.murolo
  • 146
  • 2
  • 9
0
votes
2 answers

QRegExp in C++ to capture part of string

I am attempting to use Qt to execute a regex in my C++ application. I have done similar regular expressions with Qt in C++ before, but this one is proving difficult. Given a string with optional _# at the end of the string, I want to extract the…
panofish
  • 7,578
  • 13
  • 55
  • 96
0
votes
3 answers

QRegExp problem

I have written QRegExp rx(""); RegExp in order to match kind of substring in a string, in order to…
Narek
  • 38,779
  • 79
  • 233
  • 389
0
votes
0 answers

Regular expression that recognises 3.1 and 3. as well as .1 as double

What is the right regular expression to identify a floating point number such that only the decimal point and one number is required. re = QRegExp("[-+]?[0-9]*\\.[0-9]+"); if (re.exactMatch(s)) std::cout<< "Double"<
dani
  • 3,677
  • 4
  • 26
  • 60
0
votes
2 answers

QRegularExpression to Strip ANSI Control Codes

I'm using the regular expression "\x1B[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]" to strip ANSI control codes out of a string. This works just fine with sed, but if I feed that string to a QRegularExpression it fails to match the control characters. I've…
SixDegrees
  • 781
  • 1
  • 8
  • 19
0
votes
1 answer

Select first string using QRegularExpression

How do I get the first string ("firstStr" for the examples below) using QRegularExpression QString readCmdOutput = ""; /* readCmdOutput = "firstStr\secondStr"; or readCmdOutput = "firstStr secondStr " */ readCmdOutput =…
How to
  • 103
  • 1
  • 11
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
2 answers

is it possible to split the following string using regular expressions?

suppose I have a string: QString str={time:123,age:{aaa:123,bbb:456},address:aaa,hight:{zzz:111,ccc:{rrr:333,uuu:555},xxx:222}}; is it possible using regular expression to split it to str.split(QRegExp(???)) ==> time:123 …
camino
  • 10,085
  • 20
  • 64
  • 115
0
votes
1 answer

Qregexp quantifier capture

Here is my problem i use QRegexp in the QT library to do a capture of a prolog expression like this ma(v,c). with this regular expression ([a-z][A-Za-z0-9]*)(\\()([A-Za-z0-9]*,)*([A-Za-z0-9]*)(\\))(\\.) in this case it gives me "ma" "(" "v"…
walid_salah
  • 67
  • 1
  • 2
  • 8
0
votes
1 answer

Extracting the filename off a URL with QRegExp

I have an issue where I have a RegEx, [^/\&\?]+.\w{3,4}(?=([\?&].*$|$)), but I cannot get it to work with the function at [ 1 ] below. [ 1 ] - http://doc.qt.io/qt-5/qregexp.html This is the code I've tried: QRegExp…
Phobos D'thorga
  • 439
  • 5
  • 17
0
votes
0 answers

How can I specify the QLineEdit input while typing

I wanna specify the QLineEdit input while typing that if I set the LineEdit to write text only the user can't type any numbers or symbols and so on itried to write this Name = QLineEdit(self) regex = QRegExp('([A-Z]?[a-z])') validator =…
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