Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] How to use "(" character in QRegExp to find matches in string?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SetBetterPass
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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++...

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SetBetterPass
        wrote on last edited by
        #3

        Thanks Andre it worked you saved my life :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved