Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QRegex help
Forum Updated to NodeBB v4.3 + New Features

QRegex help

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 170 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rua3n
    wrote on last edited by
    #1

    In this example:

    QStringList notFoundStrings{"0", "1"};
    
    for (const QString &string : notFoundStrings)
    {
    	QString s = QString("^.*{\\s*%1\\s*,\\s*{.*$").arg(string);
    	QRegularExpression regex(s);
    	text.remove(regex);
    }
    

    The content of text is:

            { 0, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*0$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} },
            { 0, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*1$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} },
            { 0, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*2$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} },
               
            { 1, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*3$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} },
            { 1, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*4$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} },
    
            { 544, {"test|anx|fve|229,166,18,17|229,158,42,34|?|*155$18.s0zs1Us1Us1UG30o3QY7zw7zsAzs8TsMDswvww0xy0vy0zz0zzUU"} },
            { 544, {"test|exi|gpg|161,166,20,22|140,140,52,54|132,135,154,68|*142$20.s00C003U00k00A003U00800000000001000A202s003U00DU00y00Ds03zU0zy0Dzk3zw0zzU8"} },
    
    

    Why is it not removing all lines starting with { 0, ... and { 1, ...?
    I tested the regex here and it does work.

    C 1 Reply Last reply
    0
    • R Rua3n

      In this example:

      QStringList notFoundStrings{"0", "1"};
      
      for (const QString &string : notFoundStrings)
      {
      	QString s = QString("^.*{\\s*%1\\s*,\\s*{.*$").arg(string);
      	QRegularExpression regex(s);
      	text.remove(regex);
      }
      

      The content of text is:

              { 0, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*0$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} },
              { 0, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*1$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} },
              { 0, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*2$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} },
                 
              { 1, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*3$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} },
              { 1, {"test|jgg|suw|702,305,15,19|688,299,46,35|?|*4$15.Tz7zyw3r07s0z03zUPw7M1v07zkTy3tUS03k0y0Dzzrzw7y4"} },
      
              { 544, {"test|anx|fve|229,166,18,17|229,158,42,34|?|*155$18.s0zs1Us1Us1UG30o3QY7zw7zsAzs8TsMDswvww0xy0vy0zz0zzUU"} },
              { 544, {"test|exi|gpg|161,166,20,22|140,140,52,54|132,135,154,68|*142$20.s00C003U00k00A003U00800000000001000A202s003U00DU00y00Ds03zU0zy0Dzk3zw0zzU8"} },
      
      

      Why is it not removing all lines starting with { 0, ... and { 1, ...?
      I tested the regex here and it does work.

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @Rua3n
      By default:

      • The RE dot . does not match newlines
      • A string containing multiple newlines is a single string to the RE

      Your RE tester is feeding the lines in your test string one at a time. You are feeding the RE all the input as a single string. The RE cannot match because the first newline in the string cannot be consumed by the .*

      Try:

      QRegularExpression regex(s, QRegularExpression::MultilineOption);
      

      This will not remove lines, but it will remove the text matched leaving a vestigial \n

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved