tags:

views:

153

answers:

1

Hello, I have a PCRE format regular expression: <a\s*href=\"([^<]*)\"([^<]*)\((.*?)\)\">

but i can not use it in QT, how can i convert it to QRegexp format to make it work in QT.

Thanks

+1  A: 

Did you try reading the documentation? Specifically the section called "Notes for Perl Users"? It appears that this should be pretty straightforward:

QRegExp regex( "<a\\s*href=\\"([^<]*)\\"([^<]*)\\((.*?)\\)\\">", 
    Qt::CaseSensitive, QRegExp:: RegExp2 );

Note that all I did there was double-up the backslashes, since C will "eat" one when interpreting the code. However, I have my doubts that you wanted the quotes double-backslashed, so perhaps this is more like what you wanted:

QRegExp regex( "<a\\s*href=\"([^<]*)\"([^<]*)\\((.*?)\\)\">", 
    Qt::CaseSensitive, QRegExp:: RegExp2 );

I also don't know why you are trying to match 3 quote marks in the expression, but that is beyond the scope of what you asked.

Caleb Huitt - cjhuitt
Thanks for your answer, i am not good at regular expression, i want to match some google results, but i tested my regex(<a\s*href=\"([^<]*)\"([^<]*)\((.*?)\)\">), it can match something, but when i use it in QT by using QRegExp and also use double-backslashed, i can not work. Maybe my regular expression is wrong.
tbmvp