Searching for text "Page 1 of 3"

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Searching for text "Page 1 of 3"

  • Creator
    Topic
  • #51723
    Tim Malaney
    Participant

      Trying to get the regular expression together to search an OBX for the text ”    Page n of n” where there are a number of spaces (10) prior to the word Page and “n” is always numeric. Want to eliminate the OBX since the receiving systems page breaks may be different the the sending systems.

      Thanks, Tim.

    Viewing 6 reply threads
    • Author
      Replies
      • #71455
        Chris Williams
        Participant

          In its most simple format, start with

          Code:

          Page d+ of d+

          If the leading white space is significant you can use s or s+ or s{10}, whatever is appropriate

          Code:

          s{10}Page d+ of d+

          If you know this stuff appears at the end of the line you can anchor it to the end with

          Code:

          Page d+ of d+$


          There are many good regexp/regsub references on the web. Just Google it.

        • #71456
          Tom Rioux
          Participant

            Tim,

            One small correction on the code that Chris gave you.   You will need to escape the backslash on the d , s and the curly brace.   See corrected examples below:

            hcitcl>set obx ”          Page 1 of 3″

                    Page 1 of 3

            hcitcl>regexp — “Page \d+ of \d+” $obx

            1

            hcitcl>regexp — “\s{10}Page \d+ of \d+” $obx

            1

            Hope this helps….

            Tom Rioux

          • #71457
            David Barr
            Participant

              I think that Chris was just providing the expressions, not the code to run them.  As such, they were correct.  As far as escaping the special characters, it’s probably simpler to put the entire expression in braces ({}).

            • #71458
              Tom Rioux
              Participant

                That would work too….more than one way to skin a cat as they say…..Just making sure all bases are covered…

              • #71459
                Charlie Bursell
                Participant

                  Tom:

                  As of Tcl 8.0, Tcl will pass the regular expression directly to the regular expression parser without interpretation  as long as the expression is enclosed in squirlly braces.

                  If you put double quotes the Tcl interpreter will attempt to interpret backslash escapes, square braces, etc.

                  Therfore the correct method should be:

                  regexp — {Page d+ of d+}” $obx

                  You only need the double quotes and therfore double backslashes if part of your expression is a variable since the variable would not be interpreted inside the squirrly braces

                  Note however the regexp may still not work because regular expression, by default are greedy.  That is they go for the maximum match.  Therfore if I had a statement like:  “Page 22 of 45”, the first part of the regular expression amy match all the way to the end consumng that and leaving nothing for the second part to match.  Just to be sure I would make my regular expression non-greedy like so:

                  regexp — {Page d+? of d+}” $obx  

                  I hope it makes sense   😀

                • #71460
                  Charlie Bursell
                  Participant

                    Oops,  my bad.  ðŸ˜•

                    I had an extra ” in my example.

                    Change {Page d+ of d+}”  to {Page d+ of d+}  and

                    {Page d+? of d+}”  to {Page d+? of d+}

                  • #71461
                    Tom Rioux
                    Participant

                      Perfect sense Charlie…thanks for the info!

                  Viewing 6 reply threads
                  • The forum ‘Cloverleaf’ is closed to new topics and replies.