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
2
votes
2 answers

Extracting all overlapping substrings between nested matching parentheses with a .NET regex

I'm trying to parse mathematical expressions with nested brackets: (1 * (2 - 3)) + 4 I want to get every expression in brackets, like this: (1 * (2 - 3)) (2 - 3) Using this expression: (.*?\))(?=($|[^(]+)) I'm getting this result: (1 * (2 -…
2
votes
1 answer

Regular expression for dotted string with exception

I'm not sure that is it possible to do in one regex, but it doesn't hurt to ask. I created the expression: /(?\w+)((\.(?\w+)\((?[^{}%]*)\))|(\.(?\w+)))?/i which helps me to "convert" dotted strings to…
Knowledge
  • 145
  • 1
  • 9
2
votes
1 answer

How to use Pattern, Matcher in Java regex API to remove a specific line

I have a complicate string split, I need to remove the comments, spaces, and keep all the numbers but change all string into character. If the - sign is at the start and followed by a number, treat it as a negative number rather than a operator the…
SLN
  • 4,772
  • 2
  • 38
  • 79
2
votes
1 answer

String split if the first character is minus then tread it as a negative sign

- sign can be treated as operator or negative sign. If - is located in the start, it shall be treated as the negative sign and a subtraction whiting the string. This is only apply to - sign while the + will be always the add sign. How can I achieve…
SLN
  • 4,772
  • 2
  • 38
  • 79
2
votes
0 answers

'PySide2.QtGui' has no attribute 'QRegularExpressionValidator'

I am building a ASCIIValidator with the help of the Qt c++ source code which relies on the QRegularExpression classes instead of their old QRegExp counterparts. To make an example, please take a look at line 916 of…
2
votes
1 answer

How to match nested patterns with QRegularExpression?

I'm trying to get with a QRegularExpression all one-line comments starting by a '#'. I use globalMatch and and an iterator but it doesn't manage to find the "nested comments". I use this regex : #[^\n]* And with the following code : const QString…
Maluna34
  • 245
  • 1
  • 16
2
votes
1 answer

QRegularExpression lazy matching not working for very large strings

I'm using QRegularExpression in Qt 5.10.1 to extract sections of text from files that are bound by a header and footer. For example, consider the following text: ... begin some text some more text ... end ... begin etc. I would then…
hughg
  • 191
  • 9
2
votes
1 answer

How to get every iteration of a group in a regex as a separate group?

I have a tough time figuring out a regular expression (something I have sadly almost not experience with) for the following problem: text starting with a given prefix (let's say it's ab4) text has a body of 4 blocks of 4 characters (that's what the…
rbaleksandar
  • 8,713
  • 7
  • 76
  • 161
2
votes
3 answers

Regex matching repeating digits (3 or more) ignore whitespace

I have been investigating although I have not yet managed to figure out how to create a regex that will match digits only which repeat successively 3 or more times while ignoring whitespaces. For example I have currently (\d)\1{3,} which…
PX IT
  • 45
  • 3
2
votes
1 answer

Handling accented letters in QRegularExpressions in Qt5

I am accepting input for the full name of the user using QLineEdit, and I want to accept all international characters such as "é" in French or "æ", "ø", and "å" in Norwegian, while at the same time using QRegularExpressionValidator to ensure the…
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
2
votes
1 answer

Extract a complete sentence using a QRegularExpression

I am currently trying to extract the following sentence: This is a rectangle. Its height is 193, its width is 193 and the word number is 12. from the following line: ID: 1 x: 1232 y: 2208 w: 193 h: 390 wn: 12 ln: 13 c: This is a rectangle. Its…
Dave_Dev
  • 303
  • 1
  • 12
1
vote
2 answers

Regular expression to find from the end of string

I have a few strings, like: address1 = 'Красноярский край, г Красноярск, ул Академика Вавилова, 2Д, кв. 311' address2 = 'Москва г, ул Ольховская, 45 стр. 1, квартира 3' address3 = 'Красноярский край, г Красноярск, ул Академика Вавилова, 2Д, квартира…
1
vote
2 answers

Replace a Regex look ahead for Google Big Query

I have some data for which i want to select the LAST VALUE BEFORE THE DELIMITER Example- A -> B -> C -> D In this case, i want to select "C" so i used a positive look ahead but BQ doesnt allow look aheads/behinds Here is the Regex,…
1
vote
1 answer

QRegularExpression find and capture all quoted and non-quoated parts in string

I am fairly new to using regexes. I got a string which can contain quoted and not quoted substrings. Here are examples of how they could look: "path/to/program.exe" -a -b -c "path/to/program.exe" -a -b -c path/to/program.exe "-a" "-b"…
k_k
  • 83
  • 7
1
vote
1 answer

Is 0000*1* a regular language?

If 2 L spanned from the bit alphabet. L1 = 000 L2 = 0 *1 * If we concatenate them L1L2 = 0000 *1 * I believe these 2 languages are regular because of a trivial DFA. But if you pump on L1... it would take you out of the language A non regular…
Advancedip
  • 39
  • 2
  • 4