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.

175 questions
46
votes
2 answers

Is there any difference between QRegularExpression and QRegExp?

I see there is a new class for regular expressions - QRegularExpression. Is it just a typedef for QRegExp, or a new class, or what? And why do we need it, we already have QRegExp?
sashoalm
  • 63,456
  • 96
  • 348
  • 677
4
votes
3 answers

How to replace QRegExp in a string?

I have a string. For example: QString myString = "Today is Tuesday"; The requirement is: when user types a string, if that string is contained in myString, then that part in the myString should be bold, and case insensitive (Qt::CaseInsensitive),…
songvan
  • 309
  • 3
  • 15
4
votes
3 answers

How to split QString and keep the separator in Qt?

I have a QString: "{x, c | 0x01}", and I want to split it to 7 tokens as below: { x , c | 0x01 } What's the best way to do it in Qt? I tried to use QString::split(QRegExp("[\\{\\},|]")), but it DOES NOT keep the separator in the result.
ricky
  • 1,768
  • 3
  • 15
  • 40
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…
Alexander Huszagh
  • 10,620
  • 3
  • 32
  • 59
4
votes
5 answers

How to exclude one set of words but include another in qregexp?

I am trying to exclude a group of words but include another group of words in a qregexp expression but I am currently having issues figuring this out. Here are some of the things I tried (this example included all of the…
thequerist
  • 1,624
  • 3
  • 16
  • 26
4
votes
2 answers

QRegExp match lines containing N words all at once, but regardless of order (i.e. Logical AND)

I have a file containing many lines of text, and I want to match only those lines that contain a number of words. All words must be present in the line, but they can come in any order. So if we want to match one, two, three, the first 2 lines below…
sashoalm
  • 63,456
  • 96
  • 348
  • 677
3
votes
1 answer

QRegExp just not matching! Please tell me what I'm doing wrong

I am currently working on a Qt C++ application on Mac. Throughout the application I am using string pattern matching pretty frequently. When using the QRegExp class, I keep having trouble with something that I just don't understand!!! My QRegExp…
guitarflow
  • 2,832
  • 21
  • 35
3
votes
1 answer

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
  • 309
  • 3
  • 15
3
votes
3 answers

Splitting a string with regex, ignoring delimiters that occur within braces

Suppose I have a string Max and Bob and Merry and {Jack and Co.} and Lisa. I need to split it with and being the delimiter, but only if it does not occur within curly braces. So from the above string I should get 5 strings: Max, Bob, Merry, Jack…
Maximko
  • 537
  • 5
  • 14
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
2 answers

Remove parentheses in QString

I have a QString containing "(M001)" and I want to remove the parentheses in text. The result should be "M001". How should I use a QRegExp for this?
user1020141
3
votes
0 answers

How to split QStringList with more than one delimeter?

I am trying to use split() function in QStringList I have such a file; 41761505526;31.8 55201481028;69.5 26458795084;14.2 26410796678;29.4 I want to split those numbers like; 41761505526 31.8 55201481028 69.5 26458795084 …
goGud
  • 3,647
  • 7
  • 31
  • 58
3
votes
2 answers

Qt/C++ regular expression library with unicode property support

I'm converting an application from the .Net framework to Qt using C++. The application makes extensive use of regular expression unicode properties, i.e. \p{L}, \p{M}, etc. I've just discovered that the QRegExp class lacks support for this among…
Dave Mateer
  • 16,802
  • 15
  • 90
  • 142
2
votes
3 answers

Capture multiple texts.

I have a problem with Regular Expressions. Consider we have a string S= "[sometext1],[sometext],[sometext]....,[sometext]" The number of the "sometexts" is unknown,it's user's input and can vary from one to ..for example,1000. [sometext] is some…
Evgenii.Balai
  • 889
  • 11
  • 27
2
votes
1 answer

Qt "QTextEdit" Functions

Well, i'm doing an IDE System. Basically, everything works Fine. Though, but i have a problem. The class "QTextEdit" doesn't have the member "setCompleter" which is for autocomplete. Right? Well, is some class that supports it including all…
Kazuma
  • 1,291
  • 5
  • 18
  • 33
1
2 3
11 12