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. Regular expression: Match lonely double quotes

Regular expression: Match lonely double quotes

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.2k Views 2 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    I am looking for a regular expression that matches lonely double quotes, i.e.
    abc" // <-- match
    abc"" // <-- no match

    Based on an example replacing & with &amp; from QRexExp, I tried:
    QRegExp exp(QString("\"(?!\")"));

    But that does not even match a lonely double quote.

    Where have I gone wrong?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      To ensure your double quote is single you need a lookahead and a lookbehind condition. In this case QRegExp is not the right tool. You need to switch to QRegularExpression and use "(?<!\")\"(?!\")"

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        To ensure your double quote is single you need a lookahead and a lookbehind condition. In this case QRegExp is not the right tool. You need to switch to QRegularExpression and use "(?<!\")\"(?!\")"

        A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        @SGaist
        Thank you for the hint. Strangely, I had looked through the QRegularExpression help file for lookahead, but could not find anything. Given the complexity of the class, I probably gave up too early :-)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          QRegularExpression's regexp engine is PCRE so you should be able to use features from it.

          There's also the regular expression tool that you can build and use to test your regular expressions.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

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