Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top