PDA

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



aurora
12th December 2011, 05: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

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

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

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

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

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