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

QRegExp and single-quoted text for QSyntaxHighlighter

What would the QRegExp pattern be for capturing single quoted text for QSyntaxHighlighter? The matches should include the quotes, because I am building a sql code editor. Test Pattern string1 = 'test' and string2 = 'ajsijd' So far I have…
1
vote
1 answer

How to remove the first character if it's a comma using QRegExp?

I have the following QRegExpValidator QRegExpValidator doubleValidator = new QRegExpValidator(QRegExp("[-+]?[0-9]*[\\.,]?[0-9]+([eE][-+]?[0-9]+)?")); It's supposed to be a Double numbers validator that accepts numbers, only one "e" sign, one comma…
1
vote
2 answers

Ingore string using QRegExp

I have a string in following format qString path = https://user:pass@someurl.com I want to ingore username and password from the the above path using QRegExp. An worked with following case also 1. qString path = http://user:pass@someurl. In the…
1
vote
3 answers

why does this regex does not match?

Why does the following code does not match? the expression is not that difficult and online regex tester also state that it should work. Am i doing something wrong with the escapes? QRegExp rex("(.*?)(\\d+\\.\\d+)_(\\d+\\.\\d+).*?"); QString…
vlad_tepesch
  • 6,681
  • 1
  • 38
  • 80
1
vote
1 answer

QRegExp does not operate as expected

I have a QString "mystring" which is captured from the return value from this shell command: df /storage/sdcard0/ The string captured is: Filesystem Size Used Free Blksize /storage/sdcard0/ 5.5G 3.9G …
Alan
  • 1,265
  • 4
  • 22
  • 44
1
vote
1 answer

Regexp arabic text paragraph

Given string: QString unformatted = "Some non arabic text" "بعض النصوص العربية" "Another non arabic text" "النص العربي آخر"; How to reach following result using QRegExp or other way: "

Some non arabic text

" "

بعض…

Erik Kianu
  • 89
  • 9
1
vote
1 answer

QRegExp getting Duplication in Debug Result

My Code is : QString strExp="Sum(2+3)-Sum(5+3)"; QRegExp regexp("(Sum\\([^)]*\\))"); regexp.indexIn(strExp); QStringList lst=regexp.capturedTexts(); qDebug()<<"CapturedCounts:"<
1
vote
2 answers

Need a Regular expression for text match in mysql

Hello i need a regular expression per my sql query to match to text "SIP/(10 NUMBERS)" equals "SIP/1234567890" "SIP" are text and 10 number randoms 0-9 UPDATE Final text are SIP/0123456789-000001cc where "SIP/" is text "0123456789" Always 10…
pedroooo
  • 563
  • 1
  • 4
  • 17
1
vote
4 answers

QRegExp to extract string between a tag in html

The situation is tricky as I do not have access to webkits on qt module, I am forced to parse an HTML file using QRegExp: The file contains strings which I need to extract which are well placed between li tags. If I write a QRegExp QRegExp…
1
vote
2 answers

Non greedy condition to ignore Comments in a line using QRegExp

I would like to know/have a qregexp which could extract all integers from a line but stop extracting if the digit resides in a comment section For Example { 20,100,0X0},/*this line contains 2 integers*/ My code QRegExp("(\\d+)\\}"); does the…
1
vote
2 answers

regexp for word "port" following space and number

I am working on subclassed QSyntaxHighlighter: UeSyntaxHiglighter::UeSyntaxHiglighter(QTextDocument* const parent) : QSyntaxHighlighter(parent) { UeHighlightRule ruleInfo; UeHighlightRule ruleWarning; UeHighlightRule ruleError; …
KernelPanic
  • 2,328
  • 7
  • 47
  • 90
1
vote
1 answer

QRegExp remove line with text from QString

I would like to remove all lines from a QString that have text and keep the ones that are numbers. Prior to running a regexp my QString output be as so: hello 1 world 2 if I ran something like QString.remove(QRegExp("(^[a-z]*\\n$)")) my…
bandito40
  • 597
  • 1
  • 5
  • 15
1
vote
3 answers

Using Regex, how do I extract the numbers from this serial code?

I have over 1,000 serial codes I need to enter into a database but they have to be completely numerical for conversion identification purposes. They all look similar to this format but contain different…
1
vote
1 answer

How to use both setValidator() and setInputMask() for QLineEdit in Qt?

I have a line edit where the user has to enter in the 12-hour time format. This is a touch based application and I have my own keyboard and this keyboard does not have the ":" (colon) character. So, I am using an Input Mask for that purpose. But I…
jxgn
  • 741
  • 2
  • 15
  • 36
1
vote
1 answer

QRegExp compile time warnings

I am working on some Qt app, whose main window consists of QPlainTextEdit subclassed log window for outputting events. I have three types of messages: Information message, which represents a QString that begins with [INFO] substring Warning…
KernelPanic
  • 2,328
  • 7
  • 47
  • 90