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

Regular Expression to match an exact word with any number of spaces before and after it

I want to find an exact word "SUBRECORD" with any number of spaces before and after it. I have tried: \s*SUBRECORD\s* [ ]*SUBRECORD[ ]* (\s)*SUBRECORD(\s)* but none of them work. EDIT: this is the snippet of code that's not working: QStringList…
max
  • 2,627
  • 1
  • 24
  • 44
1
vote
1 answer

QRegExp not working as expected

I have a QPlainTextEdit and want to select specific text in it using QRegExp here is example of a text block: Block1 = Foo1 { bla bla bla; bla bla bla; } I need to select starting from = till } given the sub-string Foo1 Here is my…
Mahmoud Hassan
  • 598
  • 1
  • 3
  • 15
1
vote
1 answer

QRegex not identifing "\n"

My program get configuration from comandline. the comandline is like this: "mapPath=Some_Path_Over_Here\npluginsPath=Other_Path_Over_Here\n" please notice the "\n" in the middle and in the end. my cose is: QString…
kakush
  • 3,334
  • 14
  • 47
  • 68
1
vote
2 answers

QRegexp and percent (%) sign

I'm trying to match string of the form %foo% in a template. Context: The Goal is to replace %foo% by the value of the column foo in a stored procedure return. I can't make it work. a the Beginning I tought the UTF8 encoding of my templates were the…
user2346536
1
vote
3 answers

Add two decimal digits to a number range regex

I've created a Regexp to validate a direction in degrees, between -359 and +359 (with optional sign). This is my regex: const QString xWindDirectionPattern("[+-]{0,1}([0-9]{1,2}|[12][0-9]{2}|3[0-5][0-9])"); Now, I want to add two decimal numbers,…
Jepessen
  • 11,744
  • 14
  • 82
  • 149
1
vote
1 answer

QRegExp for extracting single line comments from code

I have to extract single-line comments from qmake project file. Rules are simple: comment begins with # symbol and begin with line-break \n. So i'm read some documentation about QRegExp, and write such code to print all comments in qmake…
eraxillan
  • 1,552
  • 1
  • 19
  • 40
1
vote
1 answer

Qt C++: Line edit accept only alphanumeric characters, dash and underscore

I'm looking for the way to limit line edit to accept only alphanumeric characters, dash and underscore (in whole line could be only one dash and one underscore), without spaces. I was looking at RegExp, but then I left this option, because I found…
user1257255
  • 1,161
  • 8
  • 26
  • 55
1
vote
1 answer

Why isn't the following regexp working?

I'm trying to replace \\u0061 and \u0061 to %u0061 with QRegExp, So I did this, QString a = "\\u0061"; qDebug() << a.replace(QRegExp("\\?\\u"), "%u"); Since the slash can appear either once or twice, so I used a ? to represen the first slash, but…
daisy
  • 22,498
  • 29
  • 129
  • 265
1
vote
2 answers

Regular Expression with no LookBehind feature

I am trying to write a regular expression that looks for all ';' characters that isn't followed by a NEW LINE (\n) character. ;(?!\\\n) and all NEW LINE (\n) characters that is not preceded by a ';' character: (?< !;)\\\n Unfortunately I am using…
MPicazo
  • 691
  • 5
  • 9
1
vote
1 answer

Filter program parameters with QRegExp

I'd like to filter a command like with a QRegExp /path/to/executable --long-parameter -s /path/which/has/a/space/and/a/dash/\ -end I try to remove all the parameters that start with - and the program name (/path/to/executable) QString…
marmistrz
  • 5,974
  • 10
  • 42
  • 94
1
vote
1 answer

QLineEdit accepting only integers and ” and / characters?

I have a QLineEdit and I am using it for a measurement conversion application. In that QLineEdit I have to use only integer values, so I used the QDoubleValidator. q_LineEdit->setValidator(new QDoubleValidator(this)); Now I want the QLineEdit to…
New Moon
  • 787
  • 6
  • 21
  • 35
1
vote
1 answer

Regex expression to match C language numbers

I am trying to match numbers in Qt for syntax highlighting, and I am trying the following regexes: "[^a-fA-F_][0-9]+" // For numbers. "[^a-fA-F_][0-9]+\\.[0-9]+" // For decimal numbers. "[^a-fA-F_][0-9]+\\.[0-9]+e[0-9a-fA-F]+" // For scientific…
RenatoUtsch
  • 1,449
  • 1
  • 13
  • 20
1
vote
4 answers

Detecting text like "#smth" with RegExp (with some more terms)

I'm really bad in regular expressions, so please help me. I need to find in string any pieces like #text. text mustn't contain any space characters (\\s). It's length must be at least 2 characters ({2,}), and it must contain at least 1…
Ivan Akulov
  • 4,323
  • 5
  • 37
  • 64
0
votes
1 answer

Regular Expression for text in between tags

I have a QString that I need to parse. This QString is a QNetworkReply object obtained from an URL. I need the value 21.2401 from the QString. I am tried this. QRegExp rx("
user1065969
  • 589
  • 4
  • 10
  • 19
0
votes
1 answer

What should QString::contains(QRegExp) return? May I use position meta-characters within the RegExp?

I'm trying to detect if my input is a URL or a plain file path. I'm simply checking for http:// or www within the string, and that's enough for me. So, I'm trying QString::contains(QRegExp) and I'm finding that it doesn't return what I expect it to.…
Spidey
  • 2,508
  • 2
  • 28
  • 38