[SOLVED] How to use "(" character in QRegExp to find matches in string?



  • I have some HTML code and I want to get links from it. HTML code I have is in QString format and I want to split it by matches as href=" and url(. If I do something like:
    @QStringList lst;
    QRegExp regexp("\href=""); // " works ok
    lst = htmlCode.split(regexp);
    @
    everything works and it split my html string (later I will cut the rest and have just link without text after second " character in href="")
    but if I do
    @QStringList lst;
    QRegExp regexp("\url("); // ( fails
    lst = htmlCode.split(regexp);
    @
    string doesn't split for some reason, I see problem is with ( but I don't know why. I tried do it as regexp("\url("); and by ascii as regexp("\url\50") (wondering why it takes numbers as octal) neither worked, it just returns original string.

    I am still newbie in Qt so please help me or if there is better way to extract links from html code than I want to use I'll be happy if you guys tell me.



  • You need to double the backslash before the (. The \ is an escape character in both C++ and in regexps, so to get a single \ into your regexp, you need two in your C++. To get a double \ into your regexp (to match a literal ), you need four in C++...



  • Thanks Andre it worked you saved my life :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.