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

Qt - Split and use string from lineEdit as regExp

I want to filter all my data by typing a string, sounds simple. This is what I got so far: stringToSearch.replace( QRegExp(" "), "|" ); QRegExp regExp(stringToSearch,Qt::CaseInsensitive, QRegExp::Wildcard);…
Jedi Schmedi
  • 746
  • 10
  • 36
0
votes
2 answers

Regexp for differentiate Country, state, city given format

I have write some regexp for this but i don't get exact one. please check this link. In this i want differentiate Location field into three parts. Ref Link: https://avayacorp.authoria.net/joblist.html country State City Please give more…
Girish
  • 136
  • 1
  • 12
0
votes
1 answer

Sort with proxy model

I have a little question. I'm using QTableView with simple text items, row selection and QSortFilterProxyModel model. I reimplemented this: void MyTableView::setModel(QAbstractItemModel *model) { assert(model); …
0
votes
1 answer

QRegExp not extracting text as expected

I am trying to extract text from between square brackets on a line of text. I've been messing with the regex for some time now, and cannot get what I need. (I can't even explain why the output is what it is). Here's the code: QRegExp…
TSG
  • 4,242
  • 9
  • 61
  • 121
0
votes
1 answer

Choose only one option between double brackets QString

I want to clean up QString data to have the following: input [[normal]], here's [[double phrased|brackets]] output normal, here's double phrased Just picking the first element in each sub-brackets is fine. I am not sure what the most optimal way…
y2k
  • 65,388
  • 27
  • 61
  • 86
0
votes
1 answer

How to print a QRegExp

I have a list of QRegExp objects which are created in one part of the application, and used at some other part. They are created like: struct HighlightingRule { QRegExp pattern; // somoe more stuff... }; QStringList…
Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
0
votes
1 answer

QRegExp for HTML Image Tags

First off, I just want to say that I understand that it is a bad idea to use regexs for HTML. I'm just using it to grab tag info, so I don't care about nesting, etc. That being said, I'm trying to get the src URLs for all images in a web page.…
K. Barresi
  • 1,275
  • 1
  • 21
  • 46
0
votes
1 answer

QRegexp matching

What I am looking to do: Find all files that are of the type autogen_X.c, autogen_X.h or Project name.c (in the src folder on the root level) Print them out The QRegExp I have is: \nsrc[^\n]* The text that I have…
Arnab Datta
  • 5,356
  • 10
  • 41
  • 67
0
votes
0 answers

How to insert whitespace in an string in Qt using RegEx

I have a QString like "(ram[3].available@=> 10,2,25 &( cpu.load <> 42,49 |qweds[-1].ee0 ~\"arab lllss\" ) )" and I want to enter white space after each non-alphabetic character (i.e. @ , ~, ( and etc.) then split the string. I tried gSkinner…
mrz
  • 1,802
  • 2
  • 21
  • 32
0
votes
1 answer

Qt 4.8.4 MAC Address QRegExp

I'm trying to get Qt to match a MAC Address ( 1a:2b:3c:4d:5e:6f ) using a QRegExp. I can't seem to get it to match - what am I doing wrong? I am forcing it to try and match the string: "48:C1:AC:55:86:F3" Here are my attempts: // Define a RegEx to…
PhilBot
  • 748
  • 18
  • 85
  • 173
0
votes
1 answer

QRegExp and double-quoted text for QSyntaxHighlighter

What would the QRegExp pattern be for capturing quoted text for QSyntaxHighlighter? Test Pattern "one" or "two" or "three" So far I have tried: QRegExp rx("\\0042.*\\0042"); QRegExp rx("(\\0042).*?\\1"); The last pattern succeeds on regexpal.com…
user336063
0
votes
1 answer

Get strings from QRegex pattern (return as Stringlist / arrays)

Example: QFile controller_selected_file(loaded_file); if (controller_selected_file.open(QIODevice::ReadOnly)) { // grab a data QTextStream in(&controller_selected_file); // read all QString read_data = in.readAll(); // Regex…
Marin Sagovac
  • 3,932
  • 5
  • 23
  • 53
0
votes
2 answers

Qt QRegExp replace all URLs in a string with Anchored URLs

Given a QString that can have an unknown number of URL's in it... How can I use QRegExp to wrap HTML anchor tags around only the URL portions (with the URL itself as clickable label). e.g. input: "this is www.cnn.com, that is…
JasonGenX
  • 4,952
  • 27
  • 106
  • 198
0
votes
1 answer

Parsing texts between " " on a file to a QString

I have a text file which looks like this: VariableA = 10 VariableB = 20 VariableC = "Hello World" The code works fine, but my trouble is getting the text strings between " ". QStringList Data; Data << "VariableA = " << "VariableB = " << "VariableC…
Blastcore
  • 360
  • 7
  • 19
0
votes
3 answers

How to use QRegExp

The following piece is not working properly: QRegExp exp ("[À-Ÿà-ÿA-Za-z0-9\\-\\_]+"); if (!formatedName.contains(exp)) { success = false; } This block of code is to validate input strings entered by users. It should only accept numbers,…
peterphonic
  • 951
  • 1
  • 19
  • 38