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 6185647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:45:08+00:00 2026-05-24T01:45:08+00:00

I have a problem with Regular Expressions. Consider we have a string S= [sometext1],[sometext],[sometext]….,[sometext]

  • 0

I have a problem with Regular Expressions.

Consider we have a string

 S= "[sometext1],[sometext],[sometext]....,[sometext]"

The number of the “sometexts” is unknown,it’s user’s input and can vary from one to ..for example,1000.

[sometext] is some sequence of characters ,but each of them is not “,”,so ,we can say [^,].

I want to capture the text by some regular expression and then to iterate through the texts in cycle.

QRegExp p=new QRegExp("???");
p.exactMatch(S);
for(int i=1;i<=p.captureCount;i++)
{
  SomeFunction(p.cap(i));
}

For example,if the number of sometexts is 3,we can use something like this:

([^,]*),([^,]*),([^,]*).

So,i don’t know what to write instead of “???” for any arbitrary n.
I’m using Qt 4.7,I didn’t find how to do this on the class reference page.
I know we can do it through the cycles without regexps or to generate the regex itself in cycle,but these solutions don’t fit me because the actual problem is a bit more complex than this..

  • 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-24T01:45:09+00:00Added an answer on May 24, 2026 at 1:45 am

    A possible regular expression to match what you want is:

    ([^,]+?)(,|$)
    

    This will match string that end with a coma “,” or the end of the line. I was not sure that the last element would have a coma or not.

    An example using this regex in C#:

    String textFromFile = "[sometext1],[sometext2],[sometext3],[sometext4]";
    
    foreach (Match match in Regex.Matches(textFromFile, "([^,]+?)(,|$)"))
    {
        String placeHolder = match.Groups[1].Value;
    
        System.Console.WriteLine(placeHolder);
    }
    

    This code prints the following to screen:

    [sometext1]
    [sometext2]
    [sometext3]
    [sometext4]
    

    Using an example for QRegex I found online here is an attempt at a solution closer to what you are looking for:
    (example I found was at: http://doc.qt.nokia.com/qq/qq01-seriously-weird-qregexp.html)

    QRegExp rx( "([^,]+?)(,|$)");
    rx.setMinimal( TRUE ); // this is if the Qregex does not understand the +? non-greedy notation.
    
    int pos = 0;
    while ( (pos = rx.search(text, pos)) != -1 ) 
    {
         someFunction(rx.cap(1));
    }
    

    I hope this helps.

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

Sidebar

Related Questions

I have a problem with regular expressions! How can i count html tags with
I have a problem using preg_match. (I'm very new to regular expressions) if(preg_match('^/http:\/\/myWebsite\.com\/', $_SERVER['HTTP_REFERER']))
I have a problem with Regular Expressions. I want to replace $[.....] to ${.....}.
I have never dealt with regular expressions before, and I am facing a problem
I have a problem to build good regular expressions to find and replace. I
How I can create a regular expression for the following problem: I have a
I have a problem trying to transform a given input string to a given
I have a problem with regular expressions. I would like to match strings that
I have problem that i cant find a solution for with regular expressions, but
I want to split a string using regular expressions but I have run into

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.