Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 428493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:40:54+00:00 2026-05-12T19:40:54+00:00

I have the following regular expression that works fine in perl: Classification:\s([^\n]+?)(?:\sRange:\s([^\n]+?))*(?:\sStructural Integrity:\s([^\n]+))*\n The

  • 0

I have the following regular expression that works fine in perl:

Classification:\s([^\n]+?)(?:\sRange:\s([^\n]+?))*(?:\sStructural Integrity:\s([^\n]+))*\n

The type of data format this string is supposed to match against is:

Classification: Class Name     Range: xxxx     Structural Integrity: value
Classification: Class Name    Structural Integrity: value
Classification: Class Name

That is: the “Range” and “Structural Integrity” fields are optional. So the desired result is:

{
$& [Classification: Class Name Range: xxxx Structural Integrity: value ]
$1 [Class Name ]
$2 [xxxx ]
$3 [value ]

$& [Classification: Class Name    Structural Integrity: value ]
$1 [Class Name ]
$2 [value ]

$& [Classification: Class Name ]
$1 [Class Name ]
}

The expression uses the ? lazy quantifier in two places. This operator is not supported by QRegExp, instead Qt uses a “minimal” property which, when set to true, makes all quantifiers in an expression non-greedy

Armed with this information I write my code:

QRegExp rx("Classification:\\s([^\\n]+)(?:\\sRange:\\s([^\\n]+))*(?:\\sStructural Integrity:\\s([^\\n]+))*\\n");
rx.setMinimal(true);

But the results are incorrect, and after much tweaking I haven’t been able to get the correct captures. Is it possible to split this up into more code and less regex? Or to rewrite it without the lazy operator?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:40:54+00:00Added an answer on May 12, 2026 at 7:40 pm

    Something like this:

    QRegExp rx("(Classification|Range|Structural\\s+Integrity):|(\\S+)");
    QStringList classification();
    QStringList range();
    QStringList integrity();
    
    QStringList current = null;
    
    int pos;
    while ((pos = rx.indexIn(str, pos)) != -1) {
        if (rx.cap(1) == null) {
            if (current != null) {
                current << rx.cap(2);
            }
        }
        else if ("Classification".equals(rx.cap(1))) {
           current = classification;
        }
        else if ("Range".equals(rx.cap(1))) {
           current = range;
        }
        else if ("Structural Integrity".equals(rx.cap(1))) {
           current = integrity;
        }
        pos += rx.matchedLength();
    }
    

    It matches either valid keys followed by a colon or words. If it is a key, change the current list to the corresponding one. Otherwise add the word to the current list.

    In the end, you will have the lists classification, range and integrity, containing the words after the corresponding keys. You could join them after the full match is done:

    QString classificationString = classification.join(" ");
    

    It does not care about the order of the keys though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following regular expression: /(?<={index:)\d+(?=})/g I am trying to find index integer
I have created the following Regular Expression in C# to extract tokens from a
I have a couple of functions that I know work correctly. One just counts
I have a text box that is intended for an Email address. I am
I have the following viewmodel: public class ViewModel { [Display(Name = firstname, ResourceType =
I am trying to capture the following content in PHP using regular expressions: /*
I have to files, one is full of keywords sequences (~20k lines), the other
I have a directory with a bunch of person images in it. Unfortunately the
All of the examples I can find of urlpatterns for django sites have a
Okey, so this is my problem. I want to use mod_rewrite to make nice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.