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. QRegExp Error

QRegExp Error

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 2.9k 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.
  • E Offline
    E Offline
    ELEMENTICY
    wrote on last edited by
    #1

    Hello,im cosufing about QRegExp from QSyntaxHighlight

    this is my code of QREgExp:

    rule.pattern = QRegExp("\d[0-9]\d");
    

    it give warning
    myhighlighter.cpp:43:36: warning: unknown escape sequence '\d'

    i know what that mean but in doc.qt,io:
    https://doc.qt.io/archives/qt-4.8/qregexp.html

    its say Matches a digit,but why when i wrote it,it doesnt work

    JonBJ 1 Reply Last reply
    0
    • E ELEMENTICY

      @SGaist bcuz it will give a warning:
      myhighlighter.cpp:42:29: warning: unknown escape sequence '\W'
      and even if i ignore the warning and build.It doesnt work

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #9

      @ELEMENTICY
      We told you your original \d needed to be \\d, because of C++ literal escape characters.

      Then you decided to try //W, even though nowhere will have said to use that.

      Then @SGaist told you that you need \\W, in the same way as \\d.

      So now you decide to ignore all of the above, go for \W, and ask what it wrong.

      Have you understood anything about C++ escape character and regular expressions? It's important to under & learn from questions, not just bang bad stuff into code....

      1 Reply Last reply
      0
      • E ELEMENTICY

        Hello,im cosufing about QRegExp from QSyntaxHighlight

        this is my code of QREgExp:

        rule.pattern = QRegExp("\d[0-9]\d");
        

        it give warning
        myhighlighter.cpp:43:36: warning: unknown escape sequence '\d'

        i know what that mean but in doc.qt,io:
        https://doc.qt.io/archives/qt-4.8/qregexp.html

        its say Matches a digit,but why when i wrote it,it doesnt work

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

        @ELEMENTICY
        Why are you using QRegExp/archive doc for Qt 4.8? Are you stuck on Qt4?

        Meanwhile, think about \ inside literal C++ strings! QRegExp("\\d[0-9]\\d");

        E 2 Replies Last reply
        4
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #3

          Hi,

          Because while the regular expression itself is correct, the string is wrong. You need to escape the backslashes in it.

          Unless you are locked to Qt 4, you should migrate to QRegularExpression as QRegExp has been deprecated and removed from Qt 6.

          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
          4
          • JonBJ JonB

            @ELEMENTICY
            Why are you using QRegExp/archive doc for Qt 4.8? Are you stuck on Qt4?

            Meanwhile, think about \ inside literal C++ strings! QRegExp("\\d[0-9]\\d");

            E Offline
            E Offline
            ELEMENTICY
            wrote on last edited by
            #4

            @JonB im using qt5+

            1 Reply Last reply
            0
            • JonBJ JonB

              @ELEMENTICY
              Why are you using QRegExp/archive doc for Qt 4.8? Are you stuck on Qt4?

              Meanwhile, think about \ inside literal C++ strings! QRegExp("\\d[0-9]\\d");

              E Offline
              E Offline
              ELEMENTICY
              wrote on last edited by
              #5

              @JonB oh thx i used two \ and its work,but i notice i dont want that effect.The one i wanna use is //W (need cap) which is Matches a non-word character.

              i used two / and its not work,please help

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

                You want \W therefore it's \\W. Why use forward slashes ?

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

                E 1 Reply Last reply
                3
                • SGaistS SGaist

                  You want \W therefore it's \\W. Why use forward slashes ?

                  E Offline
                  E Offline
                  ELEMENTICY
                  wrote on last edited by
                  #7

                  @SGaist bcuz it will give a warning:
                  myhighlighter.cpp:42:29: warning: unknown escape sequence '\W'
                  and even if i ignore the warning and build.It doesnt work

                  JonBJ 1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by Christian Ehrlicher
                    #8

                    @ELEMENTICY said in QRegExp Error:

                    bcuz it will give a warning:

                    You want \W therefore it's \\W.

                    ...

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    2
                    • E ELEMENTICY

                      @SGaist bcuz it will give a warning:
                      myhighlighter.cpp:42:29: warning: unknown escape sequence '\W'
                      and even if i ignore the warning and build.It doesnt work

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #9

                      @ELEMENTICY
                      We told you your original \d needed to be \\d, because of C++ literal escape characters.

                      Then you decided to try //W, even though nowhere will have said to use that.

                      Then @SGaist told you that you need \\W, in the same way as \\d.

                      So now you decide to ignore all of the above, go for \W, and ask what it wrong.

                      Have you understood anything about C++ escape character and regular expressions? It's important to under & learn from questions, not just bang bad stuff into code....

                      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