How to match "(" in a regexp?
I want to extract the "6" from "Foo (6)" into a variable.
In for example TCL/TK I have used "\(([0-9].)\)" in such situations. But this doesn't work, the compiler complains about an unknown backslash escape sequence (obviously the "\(" and "\)").
So how can I quote the round braces?
Re: How to match "(" in a regexp?
You have to double escape the \ . It looks very nasty but it must be done:
Code:
int pos = 0;
while ((pos = rx.indexIn(s, pos)) != -1) {
qWarning() << rx.cap(1);
pos += rx.matchedLength();
}
Re: How to match "(" in a regexp?
Of course - I have to quote the "\" so that after the compiler has finished there's still a "\" there for the regexp. Thanks a lot :)