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

Regex to handle malformed delimited files

I am trying to find a regular expression that will not match a delimiter if it is wrapped in double quotes. But it must also be able to handle values that have a single double quote. I have the first part down with the below expression where…
1
vote
1 answer

QString: Remove first occurance of regular expression

QString has a method remove that takes a QRegExp. It removes every occurrence of the regular expression. Is there a way to remove only the first occurrence of the regular expression? Answer to QString replace only first occurrence doesn't help. See…
Thomas Klier
  • 449
  • 4
  • 16
1
vote
1 answer

Why doesn't this simple QRegExp match?

Very simply, here is test code which fails. QRegExp BASIC_FORMAT ("^\\s*(.+?)\\s*,\\s*(.+)\\s*$"); QString test = "Catherine the Great, Szczecin 2/5/1729 to Saint Petersburg 17/11/1796"; qDebug ("%i", BASIC_FORMAT .indexIn (test)); This prints -1,…
spraff
  • 32,570
  • 22
  • 121
  • 229
1
vote
2 answers

How to QRegExp "[propertyID="anything"] "?

I am parsing a file which contains following packets: [propertyID="123000"] { fillColor : #f3f1ed; minSize : 5; lineWidth : 3; } To scan just this [propertyID="123000"] fragment I havre this…
Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103
1
vote
2 answers

Qt LineEdit setInputMask() with setText() and QRegExp

I have a QLineEdit for Date in mm/dd/yyyy format. I am getting input using the keyboard and not using QDateEdit because of the requirement. And when the lineEdit comes to view, it has to show to the user the current date. I need the following for…
jxgn
  • 741
  • 2
  • 15
  • 36
1
vote
3 answers

Qt Regular Expression selects from first of first match to end of last match

I'm using QRegExp for geting some directories in a file. All of them start with "R:/ and finish with .c". So I used "R:/(.*).c" regex statement. But it has 1 match for below text : Text : mov f1, dsa lis r9, sdefwf "R:/frori.c" addi …
Mahmood Kohansal
  • 1,021
  • 2
  • 16
  • 42
1
vote
2 answers

Regexp find position of different characters in string

I have a string conforming to the following pattern: (cc)-(nr).(nr)M(nr)(cc)whitespace(nr) where cc is artbitrary number of letter characters, nr is arbitrary number of numerical characters, and M is is the actual letter M. For…
Freud
  • 15
  • 1
  • 3
1
vote
1 answer

QString QRegExp Remove Special Characters

I have a QString containing Latitude/Longitude data in the following format: 27° 34' 35.67" 45° 37' 28.34" I want to be able to strip/remove all the special characters (°, ', ") but I am not able to do so with the following…
1
vote
2 answers

Validate Degree and Character (Regex)

I need to validate given string from QLineEdit. True Input: 355.12° L The double number must be between 0-360, and the last character must be L or R. I have used QString mask for degree(°) and this example for 360 but i can't use mask and…
Ulfsark
  • 902
  • 1
  • 11
  • 26
1
vote
1 answer

QRegExp regular expression with quotes and blank spaces

I'm trying to get the fields of a file that looks like this: name 00 "helo-WORLD.01 " "pass " FF000000 DD111111 I'm tryign to do it with QRegExp but I dont find the regular expression that matches everything between blanks or everything inside…
republicca
  • 43
  • 1
  • 8
1
vote
1 answer

QRegExp. grab all links

I write regular expression to grab all ref links from html QRegExp bodylinksrx("(]*\\s*>[^<>]*)"); QStringList bodylinks; pos = 0; while ((pos = bodylinksrx.indexIn(htmlcode, pos)) != -1) { bodylinks <<…
Deng Won
  • 11
  • 5
1
vote
1 answer

Changing text in a QTextEdit

Hi I am trying to make a function to scan through a QTextEdit, search for email addresses and phone numbers and change them to bold. When I run it it crashes my program with error "QTextCursor::setPosition: Position '-1' out of range", here is the…
Dmon
  • 220
  • 4
  • 15
1
vote
2 answers

RegEX: need to block all backslashes and leave a forwardslash at the end

I need to pass strings like: /test/ Some illegal things would be: \test\ \test /test
user2030856
  • 77
  • 1
  • 6
1
vote
1 answer

Min Max Regex for QtCore.QRegExp

What would be a proper syntax to write a regex expression that limits a user from entering only integer numbers between a range of: 15 and 764 Thanks in advance!
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
1
vote
2 answers

Can QRegExp do MULTILINE and DOTALL match?

Recently I've been working on a PyQt program. In the beginning I used python re module to process the regex, but the transformation between python string and QString makes me confused. So I tried to change QRegExp. However, I want to use the…
Kill Console
  • 1,933
  • 18
  • 15