Results 1 to 5 of 5

Thread: what is the qt regular expression to capture the text inside a parentheses?

  1. #1
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default what is the qt regular expression to capture the text inside a parentheses?

    hi all,
    I needed to capture the text inside a parentheses.
    For eg:
    hello how are u mr(abc+d) joy

    here i want to capture the text "abc+d"
    how can i do that?
    i tried but i didnt get how to use parentheses....
    please some one guide me

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: what is the qt regular expression to capture the text inside a parentheses?

    Show us what you have so far and since parentheses are special characters, you have to escape them.

  3. #3
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: what is the qt regular expression to capture the text inside a parentheses?

    I'm trying like this...
    Qt Code:
    1. QRegExp rx("[\(]([a-z]|[0-9]|[_]|[A-Z])+[\)]");
    2. rx.indexIn(line);
    3. std::cout<<"CAPTURED IS: "<<rx.cap(0).toStdString()<<endl;
    4. captured.append(rx.cap(0));
    5. line=f.readLine();
    To copy to clipboard, switch view to plain text mode 
    i'm getting parentheses too in the captured.....but i want only text.....
    How can i do that?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: what is the qt regular expression to capture the text inside a parentheses?

    first you need to escape the slash to. second as I remember the first captured text is the whole expression. so look for the second (1) captured text. Also enclose the string inside the parentheses also with parentheses that it is captured right.


    ... and you don't need to OR []. You can just write all in a single [] block: [a-zA-Z0-9_]

  5. The following user says thank you to Lykurg for this useful post:

    aurora (12th December 2011)

  6. #5
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: what is the qt regular expression to capture the text inside a parentheses?

    ok...thank u ...

Similar Threads

  1. Regular expression help!
    By ConkerX in forum Qt Programming
    Replies: 10
    Last Post: 31st August 2011, 15:47
  2. Help with regular expression
    By Gourmet in forum General Programming
    Replies: 19
    Last Post: 11th August 2011, 15:04
  3. Regular Expression Problem
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2009, 09:41
  4. Regular expression in QLineEdit?
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 1st October 2007, 10:58
  5. Find with Regular Expression?
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2007, 14:44

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.