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. What is \o in QRegExp and how to port it to QRegularExpression?

What is \o in QRegExp and how to port it to QRegularExpression?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 582 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by Violet Giraffe
    #1

    I can't find it in any PCRE documentation. Here was my QregExp that was working fine:
    "\\b0\\o*[89]\\d*\\b"
    If I simply change it to QRegularExpression - it is invalid and the error is "missing opening brace after \o".

    It's supposed to match numeric literals in the text, including fractional numbers, and if I remove the \\o*[89] part it no longer matches the point and anything to the right of it.

    Please help.

    JonBJ 1 Reply Last reply
    0
    • V Violet Giraffe

      I can't find it in any PCRE documentation. Here was my QregExp that was working fine:
      "\\b0\\o*[89]\\d*\\b"
      If I simply change it to QRegularExpression - it is invalid and the error is "missing opening brace after \o".

      It's supposed to match numeric literals in the text, including fractional numbers, and if I remove the \\o*[89] part it no longer matches the point and anything to the right of it.

      Please help.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Violet-Giraffe
      As you can see from e.g. https://doc.qt.io/qt-5/qregexp.html#details there was never any \o character match in QRegExp. So goodness knows what it did or was supposed to do.

      Don't know whether you even verified it worked. I would start out by discovering just exactly what it did match. "numeric literals in the text, including fractional numbers" is rather vague. Positive/negative leading sign? . vs , for decimal point, bearing in mind locale? Leading digit required before this, or can be omitted? Locale-aware thousands-separator of any kind allowed or not? Why 8 or 9 optionally followed by further digits? Why would that come after "numeric literals in the text, including fractional numbers", and it seems this "fractional number" must be preceded by a 0?

      When you have decided what rules you want here you are then ready to write it as a QRegularExpression.

      V 1 Reply Last reply
      2
      • JonBJ JonB

        @Violet-Giraffe
        As you can see from e.g. https://doc.qt.io/qt-5/qregexp.html#details there was never any \o character match in QRegExp. So goodness knows what it did or was supposed to do.

        Don't know whether you even verified it worked. I would start out by discovering just exactly what it did match. "numeric literals in the text, including fractional numbers" is rather vague. Positive/negative leading sign? . vs , for decimal point, bearing in mind locale? Leading digit required before this, or can be omitted? Locale-aware thousands-separator of any kind allowed or not? Why 8 or 9 optionally followed by further digits? Why would that come after "numeric literals in the text, including fractional numbers", and it seems this "fractional number" must be preceded by a 0?

        When you have decided what rules you want here you are then ready to write it as a QRegularExpression.

        V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by Violet Giraffe
        #3

        @JonB
        Thanks, good to know it really is an obscure regex directive and I didn't just fail at googling. As you can see, QRegularExpression does handle it in some way, as there is a special check and error message for it.
        I think it means an octal number, and the [89] part allows it to match regular base 10 literals, except they still have to start with '0'? This really is weird, I'll just scrap it and rewrite from scratch as you suggested.

        P. S. I have just discovered the true purpose of ChatGPT. It must be the only entity in the world that can both write and explain regexes. Don't trust it blindly and double-check everything, but it's great help.

        JonBJ 1 Reply Last reply
        0
        • V Violet Giraffe has marked this topic as solved on
        • V Violet Giraffe

          @JonB
          Thanks, good to know it really is an obscure regex directive and I didn't just fail at googling. As you can see, QRegularExpression does handle it in some way, as there is a special check and error message for it.
          I think it means an octal number, and the [89] part allows it to match regular base 10 literals, except they still have to start with '0'? This really is weird, I'll just scrap it and rewrite from scratch as you suggested.

          P. S. I have just discovered the true purpose of ChatGPT. It must be the only entity in the world that can both write and explain regexes. Don't trust it blindly and double-check everything, but it's great help.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Violet-Giraffe
          Let's assume QRegExp accepted \o as meaning "octal digit". Then we could rewrite it as

          "\\b0[0-7]*[89]\\d*\\b"
          

          This would still be pretty odd!

          • Word boundary.
          • Literal 0.
          • Optional zero or more digits in range 0--7. [So far so good.]
          • Mandatory terminated by one of either an 8 or a 9. [Why?]
          • Optionally followed by zero or more digits in range 0--9. [Why?]
          • Word boundary.

          There is probably something there about accepting octal digits because when you write an octal number literally in C/C++ source code (may also be accepted by e.g. scanf()) you do start it with a leading 0, e.g. 012 is octal for decimal 10. But the rest of its requirements don't make sense to me.

          V 1 Reply Last reply
          1
          • JonBJ JonB

            @Violet-Giraffe
            Let's assume QRegExp accepted \o as meaning "octal digit". Then we could rewrite it as

            "\\b0[0-7]*[89]\\d*\\b"
            

            This would still be pretty odd!

            • Word boundary.
            • Literal 0.
            • Optional zero or more digits in range 0--7. [So far so good.]
            • Mandatory terminated by one of either an 8 or a 9. [Why?]
            • Optionally followed by zero or more digits in range 0--9. [Why?]
            • Word boundary.

            There is probably something there about accepting octal digits because when you write an octal number literally in C/C++ source code (may also be accepted by e.g. scanf()) you do start it with a leading 0, e.g. 012 is octal for decimal 10. But the rest of its requirements don't make sense to me.

            V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by Violet Giraffe
            #5

            Thanks for disassembling and explaining that for me. I still don't understand what it did, and I definitely don't want it in my codebase now that I see how weird it is.

            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