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

C++ Qt - QString remove() regex between {brackets}

I have tried the following regular expressions to remove {anything} between brackets (and hopefully the brackets themselves)! mystr.remove(QRegExp("\\{(.*?)\\}")); mystr.remove(QRegExp("\{(.*?)\}")); Nothing is removed
y2k
  • 65,388
  • 27
  • 61
  • 86
2
votes
2 answers

Using QRegExp replace words that are in a QString

I have a QString that contains a list of reserved words. I need to parse another string, seaching for any words that are contained in the first one and are prepended by '\' and modify these ocorrences. Example: QString reserved =…
Tyras
  • 103
  • 1
  • 7
2
votes
2 answers

Extract href value from html string using QRegExp

I am downloading a web page and I am trying to extract some values from it. The places of the page that I am interested in are of this type: and I need…
hytromo
  • 1,501
  • 2
  • 27
  • 57
2
votes
1 answer

QRegExp: individual quantifiers can't be non-greedy, but what good alternatives then?

I'm trying to write code that appends ending _my_ending to the filename, and does not change file extension. Examples of what I need to get: "test.bmp" -> "test_my_ending.bmp" "test.foo.bar.bmp" -> "test.foo.bar_my_ending.bmp" "test" …
Dmitry Frank
  • 10,417
  • 10
  • 64
  • 114
2
votes
1 answer

QScriptEngine with negative numbers, pe: 5*-2

I'm trying to run a script which evaluates only expressions that have add, subs, mults and divs, but can use negative numbers. This negative numbers are taken from instructions like this: set 1, 5 * D[5] This implies that you have to store the…
lucaslt89
  • 2,431
  • 1
  • 20
  • 30
2
votes
1 answer

Qt remove regular expression from string

I have a QString that I have replaced "=" and"," with " ". Now I would like to write a regular expression that would remove every occurrence of a certain string followed immediately by parenthesis containing a 1 to 2 character long number. For…
user1216527
  • 145
  • 1
  • 1
  • 11
2
votes
2 answers

QRegExp Pattern For URLs

I am trying to match google urls from some text that is stored in a variable, using the pattern below. The urls use double quotes QRegExp regExp; regExp.setPattern("http://www.google.com/(.*)"); I manage to match the url but it unwontedly matches…
user866190
  • 855
  • 5
  • 14
  • 31
1
vote
1 answer

regular expression with hash character

I'm having trouble recognising a potential hash character. I am using the following pattern that recognises files of the form: id-1321952010.xml. Some of these files may contain a # before the id therefore: #id-1321952010.xml need be picked up…
Will
  • 99
  • 2
  • 10
1
vote
1 answer

Qt regex not matching

Qt's regex (C++) is not working as I expect. For example, in the following line (spaces as full stops) .....mRNA............complement(join(<85666..86403,86539..>86727)) "mRNA" is not matched by: QRegExp rxItem("^\\s{5}(\\w+)") ; But is matched by…
nrhorner
  • 328
  • 6
  • 16
1
vote
3 answers

restore runtime unicode strings

I'm building an application that receives runtime strings with encoded unicode via tcp, an example string would be "\u7cfb\u8eca\u4e21\uff1a\u6771\u5317 ...". I have the following but unfortunately I can only benefit from it at compile time due to:…
Will
  • 99
  • 2
  • 10
1
vote
0 answers

Pyqt5/Pyside2 running QRegExp and QSyntaxHighlighter response very slow

It is a code made for identifying CEFR level of typing words. Basically frame see as below picture, I used QRegExp and QSyntaxHighlighter. The mainly function logic is through QSyntaxHighlighter to highlight specific words in the QPlaintextedit…
Libo
  • 11
  • 3
1
vote
1 answer

Qt QRegExp: replace spaces in a quoted string

There is a line example: text a b c text "text text1 text2" text d e f I need to replace all spaces that are inside quotes. This can be solved with simpler string operations, but I would like to solve it with QRegExp (Qt 5). After processing, I…
Dion
  • 45
  • 2
  • 6
1
vote
1 answer

Get a list of results from by conditions

I will want to get a list of resaults by this condition of reg expression: QRegExp rx( "(https://)" "(.*)" "(\\.jpg)" ); QStringList list; int pos = 0; while ((pos =…
Duracell
  • 132
  • 8
1
vote
1 answer

Is it posible to find index-row and values with QRegExp with search name?

I want to find the row-index with searching word using with QSortFilterProxyModel and QtCore.QRegExp. I want to create a list with "mobile" and "email" columns only from the row which is finding from the variable of QRegExp. Below is example…
Mano
  • 27
  • 6
1
vote
1 answer

Qt - How to extract text snippets from QString contained within a certain pattern

Take this as example QString("= LINK(aaa) + 2 + LINK(bbb) + LINK(ccc)"); I would like to find all text occurences that are contained within LINK(). In my case it should return aaa, bbb and ccc
lolo67
  • 184
  • 1
  • 1
  • 7
1 2
3
12 13