Questions tagged [qregularexpression]

The QRegularExpression class in Qt 5 and 6 provides pattern matching using regular expressions. This tag is for questions about the use of regular expressions in the Qt library. For generic questions about regular expressions, use the "regex" tag.

The QRegularExpression class provides pattern matching using regular expressions in the Qt framework.

The regular expression syntax in QRegularExpression is modeled after Perl (PCRE).

Note: This class is new in Qt 5. Qt also offers an older, slightly less capable regex implementation though the QRegExp class.

Usage example for finding all numbers in a string:

QRegularExpression re("(\\d+)");
QString str = "Offsets: 12 14 99 231 7";
QStringList list;
QRegularExpressionMatchIterator i = re.globalMatch(str);

while (i.hasNext()) {
    QRegularExpressionMatch match = i.next();
    list << match.captured(1);
}
// list: ["12", "14", "99", "231", "7"]

Read on in the official Qt documentation for Qt 5.

120 questions
0
votes
1 answer

Need QRegEx logic to split number bullet

I am trying to build a QRegEx logic to split number bullet. I tried but couldn't succeed. sample code: QString query("1. Ravi Gupta.Pari.Paagal"); QStringList list = query.split(QRegularExpression("\\(.*?\\)")); qDebug()<<"Output:…
RaviS Gupta
  • 95
  • 2
  • 11
0
votes
1 answer

Regex for array of strings

I am new to this area and am trying to write a single line regex pattern as a part of creating a json template which would accept the pattern of the 'array of strings': ["9H", "0000", "0000", "10123", "7809", "0000", "0000"] Till now, I have found…
Tisha
  • 61
  • 1
  • 2
  • 11
0
votes
2 answers

How to combine RegEx conditions?

I need to make a QLineEdit with a QRegularExpressionValidator with the following 3 constraints: Cannot start with empty space ^[\\S] Cannot start with Hello ^(?!Hello).+ Cannot end with empty space ^.*[\\S]$ How do I combine those 3 in one regex…
santahopar
  • 2,933
  • 2
  • 29
  • 50
0
votes
1 answer

I want to write a regex to match on a file content for a bank card of exact 16 digit

The card digit starts with 4366 76 TEST- 4366766586957844 -- Matched 4366763534634645 -- Matched 5123975748548665 -- Not Matched 6581436676238965347856 -- Not Matched Test-4366766586957544334235 -- Not Matched I have written…
0
votes
2 answers

Extract a specific block of text and place it in a new document

I am using EmEditor and I see there is a "find and extract to new document" function that supports Regex statements. I am trying to extract some specific text from a Thunderbird mailbox text file. In the mailbox there are copies of customer service…
Thom
  • 1
  • 5
0
votes
0 answers

Regex Python Grouping with '.*'

I have a regular expression that involves some grouping, and I am having a difficult time understanding why the last character is being grouped alone using this regex: Regex: ([A-Za-z]+).*([A-Za-z]+) String Example: Hello World I dont get why the…
lucyb
  • 333
  • 5
  • 15
0
votes
1 answer

Unable to highlight background of RegEx captured lines

I have an ultra minimal working Qt code. I want to highlight the standard multi-line style C++ comment lines starting with "/" and ending with "/". The Qt project compiles with zero warning and runs fine. But the highlighting takes place only on…
rasi
  • 11
  • 2
0
votes
1 answer

Match nested capture groups with quantifiers using QRegularExpression

I'm trying to get with a QRegularExpression all attributes of an xml tag in the different captured groups. I use a regex matching the tags and I manage to get the capture groups containing the attribute value but with a quantifier, I get only the…
Maluna34
  • 245
  • 1
  • 16
0
votes
0 answers

In stuck with QRegularexpression

I need to build a regular expression to match the following set of strings : test, tested, testing And I have the following test scenario : QRegularExpression re("^[test]{1}[ing|ed]{0,1}", QRegularExpression::CaseInsensitiveOption); QString test =…
Dmitry
  • 1,912
  • 2
  • 18
  • 29
0
votes
0 answers

QString split also splitting at '.'

I have a textField in my calculator app and I am splitting the whole input in the end to separate numbers and operators. For getting numbers I am using this: QStringList nums = displayVal.split(QRegularExpression("[\+\-\/\*]")); The problem is that…
Ayush Singh
  • 1,409
  • 3
  • 19
  • 31
0
votes
1 answer

python regular expression in pyqt qsyntaxhighlighter editor

i am building text editor with pyqt and i want to set font STYLES[error] when (") not end with another (") , and when it end correctly set font STYLES[string] , my problem is when ("") ending ... any character after ("") takes font STYLES[error] and…
Hunterx01
  • 39
  • 7
0
votes
1 answer

In QRegularExpression, what is the optimal way to get around the "lookbehind assertion is not fixed length" limitation?

Take the following regular expression: (?<=(<|<)ref) This will fail the QRegularExpression::isValid(); and QRegularExpression::errorString(); will output lookbehind assertion is not fixed length Now apparently not all Regular Expression…
Anon
  • 2,267
  • 3
  • 34
  • 51
0
votes
2 answers

QRegularExpression to Strip ANSI Control Codes

I'm using the regular expression "\x1B[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]" to strip ANSI control codes out of a string. This works just fine with sed, but if I feed that string to a QRegularExpression it fails to match the control characters. I've…
SixDegrees
  • 781
  • 1
  • 8
  • 19
0
votes
1 answer

QRegularExpression how i can get last matched word

(?i)time.?([0-9:]+) - this pattern find all texts - time=00:00:00.00 How i can get last matched element(time=00:05:01.84) in first or second text First text: Metadata: creation_time : 2013-11-21 11:03:11 handler_name : IsoMedia…
How to
  • 103
  • 1
  • 11
0
votes
1 answer

Complex Regular Expression - Change HTML words into links that search that word

I have 1000+ pages I need to turn certain words into links containing said word(s). Basically wondering how I could use Regular Expression to do something like... change. PRODUCTS / SERVICES:
Sean Carroll
  • 107
  • 1
  • 14