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
0 answers

QString split() function with QRegExp strange behaviour

I have some text like this: "1.801908\t20.439980\t\r\n25.822865\t20.439305\t\r\n26.113739\t4.069647\t\r\n1.800252\t4.301690\t\r\n" I want to split this text by lines and then by tabs. I am using QString split() function and QRegExp to do that in…
TinF
  • 89
  • 7
0
votes
0 answers

Get Image URL From String

I am trying to figure out a way to get a image url from a web page source. I can get the web page source into a string and parse it line by line to find the line with the URL. However, I haven't been able to figure out a good way to pull just the…
Talon06
  • 1,756
  • 3
  • 27
  • 51
0
votes
1 answer

Regular Expression gives wrong matches in QRegEx

I have the following function which should give me the matched string from a regular expression: QString selectByPattern(QString const &oValue, QString const &oPattern, bool bRegularExpression) const { QString s; QRegExp regex; //…
Devolus
  • 21,661
  • 13
  • 66
  • 113
0
votes
1 answer

Search for UTF encoded characters using QRegExp

I'm trying to check for characters §£¤ using QRegExp. QString string = "§¤£"; int res = string.count(QRegExp("[§¤£]")); And the res returns 0.
twin
  • 1
  • 1
0
votes
1 answer

QRegExp For QSortFilterProxyModel - Find All Items In A List

Am using PyQt & getting stuck on using setFilterRegExp() with a QSortFilterProxyModel. The source model outputs integers 1-30, and the QSFPM is to filter 1-30, leaving only the numbers in a supplied list. proxy.setFilterRegExp(QRegExp('^%s{1,1}%' %…
user2422819
  • 177
  • 13
0
votes
1 answer

QRegExp - How to get specific text between two HTML tags

I want to extract some text from the following HTML code in "Qt/C++" using QRegExp.
MCT-to-KR
Alaa Salah
  • 1,047
  • 3
  • 12
  • 28
0
votes
3 answers

QRegExp match certain letters?

I'm working with DNA, RNA and protein sequences and QRegExp doesn't work for me to detect if the sequence contains only certain characters. For example unambiguous contains only acgt : seq.contains(QRegExp("[gatc]")) Doesn't work for me. How can I…
alrawab
  • 217
  • 3
  • 8
0
votes
1 answer

How to use QRegExp when there is only one bckslash?

I want to use QRegExp to detect Postgres like regular expressions. For QRegExp, doc says "To include a \ in a regexp, enter it twice, i.e. \" Example: dollar amount: \$[0-9]+.[0-9][0-9] To successfully match this using QRegExp, it should be have two…
user1819676
  • 369
  • 1
  • 12
0
votes
1 answer

How to allow "*" and number only in Regular Expression : Qt5.2

I want to allow * or Number only in my QLineEdit for IP Address. My regular Expression is: QRegExp rx ( "^(0|[1-9]|[1-9][0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$" ); Which is find for IP Address, Now I want to allow * symbol for search IP Range. i.e.…
AB Bolim
  • 1,997
  • 2
  • 23
  • 47
0
votes
1 answer

qt regex to boost regex conversion for taking number from inside a string

I've have a method in a class that takes a QString and, using a regular expression, it return the first float number (positive or negative) included into the string. This is the method: float MyClass::getNumberFromQString(const QString &xString) { …
Jepessen
  • 11,744
  • 14
  • 82
  • 149
0
votes
1 answer

Qt5 Qregexp : why my pattern can't work?

I get this problem When I open a text file, I can't get any matched string. Then I test this pattern: .* but I can either get nothing. I'm sure the text file can be read, and the pattern can be accepted in grep. Thank you. QList
mtfly
  • 35
  • 6
0
votes
1 answer

Regex for extracting qmake variables

I'm trying to write the QRegExp for extracting variable names from qmake project code (*.pro files). The syntax of variable usage have two forms: $$VAR $${VAR} So, my regular expression must handle both cases. I'm trying to write expression in…
eraxillan
  • 1,552
  • 1
  • 19
  • 40
0
votes
1 answer

QRegExp capture and replace

I have a string @echo Setting environment for using the GDAL Utilities. set GDAL_PATH="G:\MapTiler" @echo GDAL path is %GDAL_PATH%. set PATH=%GDAL_PATH%;%PATH% in this i want to extract "G:\MapTiler" and replace it with…
0
votes
1 answer

QRegExp to find nth character NOT in a HTML tag

Lets say I have a string such as this: Blah is here and here And I want to get the index in the string of the 7th character that isn't part of a HTML tag (the "i"). I know I'll be able to do this…
gremwell
  • 1,419
  • 17
  • 23
0
votes
1 answer

QRegExp does not recognize expression

I have the following input: (&xxx-&yyyy) &pp_pp+&uuu I'm trying to get all matches which starts with an & and are followed by any word character. E.g. above should yield to: &xxx &yyyy &pp_pp &uuu What I tried is: QRegExp rx; …
Stephan
  • 15,704
  • 7
  • 48
  • 63