View Full Version : what is the qt regular expression to capture the text inside a parentheses?

12th December 2011, 06:02
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

12th December 2011, 07:20
Show us what you have so far and since parentheses are special characters, you have to escape them.

12th December 2011, 07:34
I'm trying like this...

QRegExp rx("[\(]([a-z]|[0-9]|[_]|[A-Z])+[\)]");
std::cout<<"CAPTURED IS: "<<rx.cap(0).toStdString()<<endl;
i'm getting parentheses too in the captured.....but i want only text.....
How can i do that?

12th December 2011, 07:58
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_]

12th December 2011, 08:32
ok...thank u ...:)