×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    12

    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
    Regular Contributor
    Join Date
    Apr 2011
    Posts
    89

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

    Try Detailed Description section in this article

    http://doc.qt.nokia.com/latest/qregexp.html

  3. #3
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

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

    You cannot escape parenthesis with \. To escape them I define them as character: [(].
    Below you can find the entire regexp and the code.

    Here few notes to understand better the regexp I wrote
    - [(] matches "("
    - .* matches any character.
    - (.*) means you want to capture the text inside the parenthesis.
    - list[0] returns the entire string
    - list[1] return the text you want to capture.

    QString str = "hello how are u mr(abc+d) joy";
    QRegExp rx("[(](.*)[)]");
    int pos = rx.indexIn(str);
    QStringList list = rx.capturedTexts();
    qDebug() << list[1];

Similar Threads

  1. Regular Expression
    By MobiSecLap in forum Symbian
    Replies: 16
    Last Post: 2010-03-26, 09:08
  2. version regular expression
    By dudi in forum [Closed] Publishing to Nokia Store
    Replies: 1
    Last Post: 2009-08-20, 18:47
  3. validate text box with regular expression
    By mt.jijo in forum Symbian
    Replies: 3
    Last Post: 2009-06-22, 17:35
  4. Replies: 3
    Last Post: 2008-08-01, 07:26
  5. Regular Expression
    By ohyeeloon in forum Symbian
    Replies: 1
    Last Post: 2007-01-08, 05:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×