Results 1 to 6 of 6

Thread: How to split string using QRegex?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2015
    Posts
    109
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to split string using QRegex?

    Thanks,

    I have tried with other way, but it has small issue, look the code below,
    Qt Code:
    1. QString query("{($..Properties[*])-($..Layer_Index)}");
    2. QRegularExpression re;
    3. re.setPattern("\\(.*?\\)");
    4. QRegularExpressionMatch match = re.match(query);
    5. qDebug()<<"Match 0: "<<match.captured(0);
    6. qDebug()<<"Match 1: "<<match.captured(1);
    7.  
    8. //Output: Match 0: "($..Properties[*])"
    9. // Match 1: ""
    To copy to clipboard, switch view to plain text mode 

    Here I didnt get the Match 1 as ($..Layer_Index), why ?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to split string using QRegex?

    For one thing, QRegularExpressionMatch::captured() with a '0' argument returns the -entire- capture, not the first one. captured( 1 ) should be returning your first string, not the second. QRegularExpressionMatch::capturedTexts() will return all of them as a QStringList.

    And try using QRegularExpression::globalMatch() instead of match().
    Last edited by d_stranz; 14th April 2020 at 16:57.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. how to split a big string?
    By aurora in forum Newbie
    Replies: 2
    Last Post: 21st February 2012, 06:10
  2. Split string
    By mero in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2011, 19:17
  3. split camel case string
    By GrahamLabdon in forum Newbie
    Replies: 5
    Last Post: 1st February 2011, 16:37
  4. How to split a string line
    By grsandeep85 in forum Newbie
    Replies: 5
    Last Post: 29th July 2009, 10:42
  5. How to split a string line
    By grsandeep85 in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 10:28

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.