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. Find QRegExp in the text
Forum Updated to NodeBB v4.3 + New Features

Find QRegExp in the text

Scheduled Pinned Locked Moved General and Desktop
13 Posts 5 Posters 6.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.
  • F Offline
    F Offline
    Franzk
    wrote on last edited by
    #4

    Might the cursor then be at the document end?

    "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

    http://www.catb.org/~esr/faqs/smart-questions.html

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #5

      Curly brackets have a special meaning in regular expressions. You need to escape them like this:

      @
      QRegExp re("\{. \}");
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Ruzik
        wrote on last edited by
        #6

        I find my mistake
        @ if (!plainTextEdit->document()->find(QRegExp("\{ *\}")).isNull())
        listWidget->addItem("empty stylesheet {it's empty!}");@
        And code work, but it is not work with sign of new string(\n), how can i modif my QRegExp to my code work, i try

        @
        QRegExp("\{[ \Z]\}"))
        QRegExp("\{[ \Z]
        \}"))
        @

        And instead Z i try use A
        All does not work

        [EDIT: wrap your code!, Volker]

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ruzik
          wrote on last edited by
          #7

          I also try QRegExp(”\{[ \n]*\}”))

          1 Reply Last reply
          0
          • S Offline
            S Offline
            soroush
            wrote on last edited by
            #8

            AFAIK you can apply a regular expression in a single text block only. That is you cannot use \n notation with your regexp. I remember that in my homework I had to break my expression to two expressions to do that. I didn't found a way to use a regexp with two paragraphs in QPlainTextEdit....

            you can use "this tool":http://sourceforge.net/projects/regexer to test regular expressions in Qt.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Ruzik
              wrote on last edited by
              #9

              But there are operators \A and \Z - start and end of string in the QRegExp, so in QRegExp must work with it

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #10

                [quote author="Ruzik" date="1307644633"]I also try

                @
                QRegExp(”\{[ \n]*\}”))[/quote]
                @

                [EDIT: code formatting! Volker]

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  soroush
                  wrote on last edited by
                  #11

                  QRegExp works with \n and so on but in QPlainTextEdit it's applied on a text block. not whole contents of QPlainTextEdit. you probably need to break your expression or use that on the QPlainTextEdit::toPlainText() to find begin and end indexes.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #12

                    The search pattern is only applied for a text block. The pattern can not cross a text block boundary! See method static bool findInBlock() around line 1290 in qtextdocument.cpp of the Qt sources.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dcortesi
                      wrote on last edited by
                      #13

                      The answers above explain a problem I came to ask about, so thank you. However, in the general case of a user-entered pattern I do not see any way of getting around this bad restriction.

                      Suppose the pattern (example from QRegExp documentation) is <b>.*</b>, this cannot succeed when the document is:

                      @
                      some text or <b>bold
                      text</b> other etc.
                      @

                      You could examine the user's pattern and change it into:

                      @
                      <b>.$
                      ^.
                      </b>
                      @

                      But that would fail for the case of <b>on one line</b> and also would fail for the case of a target spanning three or more lines. In short I see no work-around for the general case of patterns matching across multiple lines. Comment?

                      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