• Login
Community
  • Login

Pythonscript search different than N++ search when using \< and leading uppercase

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
25 Posts 5 Posters 13.3k Views
Loading More Posts
  • 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.
  • C
    Claudia Frank @Alan Kilborn
    last edited by Feb 8, 2017, 3:50 PM

    @Alan-Kilborn

    I’m in the same mood.

    I will try to see if I understand what npp is really doing under the hood.
    Maybe it is just replacing the (?i) with flags then the
    obvious solution would be to parse a regex for the flags and
    setting it explicitly, if using pythonscript, to get the same results.

    I will follow-up on this.

    Cheers
    Claudia

    1 Reply Last reply Reply Quote 0
    • M
      MAPJe71
      last edited by MAPJe71 Feb 8, 2017, 3:57 PM Feb 8, 2017, 3:54 PM

      Python 2.7.x does not interpret \< and \> as word boundaries.
      Verified it with RegexBuddy by changing the Application (Regex Flavor) from boost::regex 1.58-1.59 to python 2.7.

      C 1 Reply Last reply Feb 8, 2017, 3:56 PM Reply Quote 0
      • C
        Claudia Frank @MAPJe71
        last edited by Feb 8, 2017, 3:56 PM

        @MAPJe71

        yes, but research is not using python engine it is using boost engine, afaik.

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 0
        • C
          Claudia Frank
          last edited by Feb 8, 2017, 5:06 PM

          quick update
          I assume I found the difference and some glitch (depends on view).

          If searching by npp find/reaplce dialog the standard is ignorecase.
          Flag matchcase is only set if checkbox is checked (makes sense)

          If searching via pythonscript and research than standard is matchcase.
          Only if flag re.I is provided it does ignoring the case (again, makes sense)

          Our assumption was that regardless what has been selected, the usage of
          (?i) does mean that it will treat it as ignorecase and this is not the case.

          If you do a search via the npp dialog using matchcase checkbox and (?i)
          you will see that it uses the matchcase instead of ignorecase.

          So - at the moment I would say, both behave the same.

          I will do some further tests later.

          Cheers
          Claudia

          S 1 Reply Last reply Feb 8, 2017, 6:37 PM Reply Quote 0
          • S
            Scott Sumner @Claudia Frank
            last edited by Scott Sumner Feb 8, 2017, 6:39 PM Feb 8, 2017, 6:37 PM

            @Claudia-Frank said:

            If you do a search via the npp dialog using matchcase checkbox and (?i)
            you will see that it uses the matchcase instead of ignorecase.

            Okay, so now I’m confused. If I try a very simple interactive search (forget the \< thing discussed earlier), where I lead off the Find-what box with (?i), it makes no difference whether the “match case” checkbox is checked or not, my simple search gets matches that ignore case. @Claudia-Frank , doesn’t this result go against what you just said?

            C 1 Reply Last reply Feb 8, 2017, 7:15 PM Reply Quote 0
            • C
              Claudia Frank @Scott Sumner
              last edited by Feb 8, 2017, 7:15 PM

              @Scott-Sumner

              No, if you take into account that research is resulting the same but
              yes if you took that statement in general.
              I’m comparing npp dialog search and python script research results.

              But you are right, confusing!

              From testing it seems that research and npp search behave the same
              if flags are set the same.

              Cheers
              Claudia

              A 1 Reply Last reply Feb 8, 2017, 9:13 PM Reply Quote 0
              • A
                Alan Kilborn @Claudia Frank
                last edited by Feb 8, 2017, 9:13 PM

                @Claudia-Frank , do you still have more testing to do, or have you taken it as far as it can go? If you are done, then I have questions. :)

                The main question is, should the golden rule be, when writing Pythonscript, to forget about embedding (?i) at the front of a regular expession string, and setting the flags parameter to re.IGNORECASE (or re.I, or even 2) to get the behavior that is desired?

                I always liked using (?i) because that way, when reading a regex from left to right, I could prepare myself properly, rather than having to look for a somewhat disconnected flags parameter. But, if things aren’t going to work right, I can learn another way.

                However, I’m still confused about what I should do to make things work right in all cases… :(

                C 1 Reply Last reply Feb 8, 2017, 9:35 PM Reply Quote 0
                • C
                  Claudia Frank @Alan Kilborn
                  last edited by Feb 8, 2017, 9:35 PM

                  @Alan-Kilborn ,
                  at the moment, it looks like my last statement about the flags and if set the same seems to be correct.
                  But this could mean I just haven’t found the regex which breaks it again or it is simply true.
                  I like to tend to the latter :-)

                  Does it matter in regards to your script?
                  I assume, only if you want to compare with the interactive search dialog or
                  when creating the regex with the dialog and afterwards using it in a script.

                  If my statement about the flags is true, and you want to have the script behave exactly the same
                  as npps find dialog does, then you need to provide the flags as npp does.

                  I do see the advantage of using the modifiers but it looks like that neither pythonscript
                  nor npp do it right in terms of the issue you found.

                  Cheers
                  Claudia

                  A 1 Reply Last reply Feb 9, 2017, 12:57 PM Reply Quote 0
                  • C
                    Claudia Frank
                    last edited by Feb 8, 2017, 11:01 PM

                    OK, from my point of view it looks like it is how I’ve described already.
                    If npp find dialog and pythonscript research are using the same flags and regex,
                    the result is the same.

                    So, python script users needs to be aware that npp sets the ignorecase flag
                    per default.

                    If someone finds different behavior - please report.

                    Cheers
                    Claudia

                    1 Reply Last reply Reply Quote 0
                    • A
                      Alan Kilborn @Claudia Frank
                      last edited by Feb 9, 2017, 12:57 PM

                      @Claudia-Frank said:

                      Does it matter in regards to your script?

                      Well…what matters in regards to my script is that the regex search works correctly. The discussion about interactive versus scripted search and embedded flags versus separate flags is nice, but…

                      The bottom line is that the scripted search has a problem, and that problem is seemingly related to the use of \< and \> in the regex, which I would like to be able to use. So, okay, we can “fix” that by working around it by playing with the flags stuff, and that is all fine, I guess.

                      But should that become a general rule for using Pythonscript’s re.search() function, based upon someone finding one weird case? Maybe there is no great answer to that at this point, but I’m attempting to create something general purpose, where I can’t test all possible regexes for how they work at coding time, as they are input at run-time.

                      So I’m left wondering if the best thing to do when coding with editor.research() is to never embed (?i) or (?-i) in the regex, and instead always use the flags parameter. Perhaps based upon the data we have at this moment, that is the best course of action.

                      C 1 Reply Last reply Feb 9, 2017, 10:30 PM Reply Quote 0
                      • C
                        Claudia Frank @Alan Kilborn
                        last edited by Feb 9, 2017, 10:30 PM

                        @Alan-Kilborn

                        Well…what matters in regards to my script is that the regex search works correctly.

                        More philosophic, what means correct if we talk about regex.
                        As long as the same regex can be interpreted differently by different regex engines
                        how can we be sure what is right or wrong.

                        I agree, I assumed too, that using the modifiers overrules the flags but with the regex
                        you used we see it isn’t. I don’t know if this is a bug in the implementation of the boost
                        regex engine or a bug of the boost regex engine. I don’t think that I will go in that detail.

                        Concerning the correctness of the scripts - you found one misbehavior, I’m quite certain that others exist.

                        The bottom line is that the scripted search has a problem, and that problem is seemingly related to the use of < and > in the regex

                        Just to be clear, both, npp and pythonscript behave the same. It is not only python script which does this.

                        which I would like to be able to use. So, okay, we can “fix” that by working around it by playing with the flags stuff, and that is all fine, I guess.

                        From the test it looks like only the “start of word” and “end of word” word boundaries behave strange.
                        If you stop using this particular item you might have already solved it.
                        Until you discover the next issue.

                        But should that become a general rule for using Pythonscript’s re.search() function, based upon someone finding one weird case?
                        Maybe there is no great answer to that at this point, but I’m attempting to create something general purpose,
                        where I can’t test all possible regexes for how they work at coding time, as they are input at run-time.
                        So I’m left wondering if the best thing to do when coding with editor.research() is to never embed (?i) or (?-i) in the regex,
                        and instead always use the flags parameter. Perhaps based upon the data we have at this moment, that is the best course of action.

                        Personally, I’m avoiding now using the modifiers in scripts and using flags when needed.

                        Cheers
                        Claudia

                        1 Reply Last reply Reply Quote 0
                        • M
                          MAPJe71
                          last edited by Feb 9, 2017, 10:39 PM

                          Wondering if it’s only an issue with editor.research( ... ), as I have been using modifiers with editor.rereplace( ... ) successfully.

                          C 1 Reply Last reply Feb 9, 2017, 10:48 PM Reply Quote 0
                          • C
                            Claudia Frank @MAPJe71
                            last edited by Claudia Frank Feb 9, 2017, 10:49 PM Feb 9, 2017, 10:48 PM

                            @MAPJe71

                            Yep - same issue.

                            New doc with the word Print only

                            editor.rereplace('(?i)\<print\>', 'PRINT')
                            

                            fails where

                            editor.rereplace('\<print\>', 'PRINT', 2)
                            

                            works

                            UUhhh - I should avoid magic numbers - 2=re.I

                            Cheers
                            Claudia

                            1 Reply Last reply Reply Quote 0
                            • M
                              MAPJe71
                              last edited by Feb 10, 2017, 12:41 AM

                              UUhhh - I should avoid magic numbers - 2=re.I

                              Damn right!!! LOL

                              1 Reply Last reply Reply Quote 0
                              • G
                                guy038
                                last edited by guy038 Feb 11, 2017, 7:27 PM Feb 11, 2017, 7:09 PM

                                Hi, All,

                                I did some tests, using the classical Find dialog, with the original text, below :

                                xyz
                                xYz
                                xyZ
                                xYZ
                                Xyz
                                XYz
                                XyZ
                                XYZ
                                -----
                                1xyz
                                1xYz
                                1xyZ
                                1xYZ
                                1Xyz
                                1XYz
                                1XyZ
                                1XYZ
                                -----
                                xyz9
                                xYz9
                                xyZ9
                                xYZ9
                                Xyz9
                                XYz9
                                XyZ9
                                XYZ9
                                -----
                                1xyz9
                                1xYz9
                                1xyZ9
                                1xYZ9
                                1Xyz9
                                1XYz9
                                1XyZ9
                                1XYZ9
                                

                                Then I tested the different regexes

                                • xYZ

                                • xYZ\>

                                • xYZ\b

                                • \<xYZ

                                • \bxYZ

                                • \<xYZ\>

                                • \bxYZ\b

                                • (^|(?<=\W))xYZ((?=\W)|$)

                                • With the Match case option ON

                                • With the Match case option OFF

                                • Preceded by (?i) and with the Match case option ON

                                • Preceded by (?i) and with the Match case option OFF

                                • Preceded by (?-i) and with the Match case option ON

                                • Preceded by (?-i) and with the Match case option OFF

                                I obtained the six following tables, where :

                                • A correct match is indicated by a * character

                                • An incorrect match is indicated by the E letter ( Error )


                                +-------+------------------------------------------------------------------------------------+
                                |       |            Option "Match case"  ON           and           Regex, below            |
                                | Text  |-----+-------+-------+-------+-------+---------+---------+--------------------------|
                                |       | xYZ | xYZ\> | xYZ\b | \<xYZ | \bxYZ | \<xYZ\> | \bxYZ\b | (^|(?<=\W))xYZ((?=\W)|$) |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | xyz   |     |       |       |       |       |         |         |                          |
                                | xYz   |     |       |       |       |       |         |         |                          |
                                | xyZ   |     |       |       |       |       |         |         |                          |
                                | xYZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | Xyz   |     |       |       |       |       |         |         |                          |
                                | XYz   |     |       |       |       |       |         |         |                          |
                                | XyZ   |     |       |       |       |       |         |         |                          |
                                | XYZ   |     |       |       |       |       |         |         |                          |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | 1xyz  |     |       |       |       |       |         |         |                          |
                                | 1xYz  |     |       |       |       |       |         |         |                          |
                                | 1xyZ  |     |       |       |       |       |         |         |                          |
                                | 1xYZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1Xyz  |     |       |       |       |       |         |         |                          |
                                | 1XYz  |     |       |       |       |       |         |         |                          |
                                | 1XyZ  |     |       |       |       |       |         |         |                          |
                                | 1XYZ  |     |       |       |       |       |         |         |                          |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | xyz9  |     |       |       |       |       |         |         |                          |
                                | xYz9  |     |       |       |       |       |         |         |                          |
                                | xyZ9  |     |       |       |       |       |         |         |                          |
                                | xYZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | Xyz9  |     |       |       |       |       |         |         |                          |
                                | XYz9  |     |       |       |       |       |         |         |                          |
                                | XyZ9  |     |       |       |       |       |         |         |                          |
                                | XYZ9  |     |       |       |       |       |         |         |                          |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | 1xyz9 |     |       |       |       |       |         |         |                          |
                                | 1xYz9 |     |       |       |       |       |         |         |                          |
                                | 1xyZ9 |     |       |       |       |       |         |         |                          |
                                | 1xYZ9 |  *  |       |       |       |       |         |         |                          |
                                | 1Xyz9 |     |       |       |       |       |         |         |                          |
                                | 1XYz9 |     |       |       |       |       |         |         |                          |
                                | 1XyZ9 |     |       |       |       |       |         |         |                          |
                                | 1XYZ9 |     |       |       |       |       |         |         |                          |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                
                                
                                +-------+------------------------------------------------------------------------------------+
                                |       |            Option "Match case"  OFF          and           Regex, below            |
                                | Text  |-----+-------+-------+-------+-------+---------+---------+--------------------------|
                                |       | xYZ | xYZ\> | xYZ\b | \<xYZ | \bxYZ | \<xYZ\> | \bxYZ\b | (^|(?<=\W))xYZ((?=\W)|$) |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | xyz   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | xYz   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | xyZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | xYZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | Xyz   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | XYz   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | XyZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | XYZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | 1xyz  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1xYz  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1xyZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1xYZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1Xyz  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1XYz  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1XyZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1XYZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | xyz9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | xYz9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | xyZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | xYZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | Xyz9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | XYz9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | XyZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | XYZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | 1xyz9 |  *  |       |       |       |       |         |         |                          |
                                | 1xYz9 |  *  |       |       |       |       |         |         |                          |
                                | 1xyZ9 |  *  |       |       |       |       |         |         |                          |
                                | 1xYZ9 |  *  |       |       |       |       |         |         |                          |
                                | 1Xyz9 |  *  |       |       |       |       |         |         |                          |
                                | 1XYz9 |  *  |       |       |       |       |         |         |                          |
                                | 1XyZ9 |  *  |       |       |       |       |         |         |                          |
                                | 1XYZ9 |  *  |       |       |       |       |         |         |                          |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                
                                
                                +-------+------------------------------------------------------------------------------------+
                                |       |       Option "Match case"  ON       and       Regex, below, PRECEDED by (?i)       |
                                | Text  |-----+-------+-------+-------+-------+---------+---------+--------------------------|
                                |       | xYZ | xYZ\> | xYZ\b | \<xYZ | \bxYZ | \<xYZ\> | \bxYZ\b | (^|(?<=\W))xYZ((?=\W)|$) |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | xyz   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | xYz   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | xyZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | xYZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                | Xyz   |  *  |   *   |   *   |   E   |   *   |    E    |    *    |            *             |
                                | XYz   |  *  |   *   |   *   |   E   |   *   |    E    |    *    |            *             |
                                | XyZ   |  *  |   *   |   *   |   E   |   *   |    E    |    *    |            *             |
                                | XYZ   |  *  |   *   |   *   |   E   |   *   |    E    |    *    |            *             |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | 1xyz  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1xYz  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1xyZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1xYZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1Xyz  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1XYz  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1XyZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                | 1XYZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | xyz9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | xYz9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | xyZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | xYZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                | Xyz9  |  *  |       |       |   E   |   *   |         |         |                          |
                                | XYz9  |  *  |       |       |   E   |   *   |         |         |                          |
                                | XyZ9  |  *  |       |       |   E   |   *   |         |         |                          |
                                | XYZ9  |  *  |       |       |   E   |   *   |         |         |                          |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                | 1xyz9 |  *  |       |       |       |       |         |         |                          |
                                | 1xYz9 |  *  |       |       |       |       |         |         |                          |
                                | 1xyZ9 |  *  |       |       |       |       |         |         |                          |
                                | 1xYZ9 |  *  |       |       |       |       |         |         |                          |
                                | 1Xyz9 |  *  |       |       |       |       |         |         |                          |
                                | 1XYz9 |  *  |       |       |       |       |         |         |                          |
                                | 1XyZ9 |  *  |       |       |       |       |         |         |                          |
                                | 1XYZ9 |  *  |       |       |       |       |         |         |                          |
                                +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                
                                
                                
                                1 Reply Last reply Reply Quote 1
                                • G
                                  guy038
                                  last edited by guy038 Feb 11, 2017, 7:30 PM Feb 11, 2017, 7:21 PM

                                  I need to split this post in two parts because it exceeds 16384 characters !

                                  +-------+------------------------------------------------------------------------------------+
                                  |       |       Option "Match case"  OFF       and       Regex, below, PRECEDED by (?i)      |
                                  | Text  |-----+-------+-------+-------+-------+---------+---------+--------------------------|
                                  |       | xYZ | xYZ\> | xYZ\b | \<xYZ | \bxYZ | \<xYZ\> | \bxYZ\b | (^|(?<=\W))xYZ((?=\W)|$) |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | xyz   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                  | xYz   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                  | xyZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                  | xYZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                  | Xyz   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                  | XYz   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                  | XyZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                  | XYZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | 1xyz  |  *  |   *   |   *   |       |       |         |         |                          |
                                  | 1xYz  |  *  |   *   |   *   |       |       |         |         |                          |
                                  | 1xyZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                  | 1xYZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                  | 1Xyz  |  *  |   *   |   *   |       |       |         |         |                          |
                                  | 1XYz  |  *  |   *   |   *   |       |       |         |         |                          |
                                  | 1XyZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                  | 1XYZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | xyz9  |  *  |       |       |   *   |   *   |         |         |                          |
                                  | xYz9  |  *  |       |       |   *   |   *   |         |         |                          |
                                  | xyZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                  | xYZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                  | Xyz9  |  *  |       |       |   *   |   *   |         |         |                          |
                                  | XYz9  |  *  |       |       |   *   |   *   |         |         |                          |
                                  | XyZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                  | XYZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | 1xyz9 |  *  |       |       |       |       |         |         |                          |
                                  | 1xYz9 |  *  |       |       |       |       |         |         |                          |
                                  | 1xyZ9 |  *  |       |       |       |       |         |         |                          |
                                  | 1xYZ9 |  *  |       |       |       |       |         |         |                          |
                                  | 1Xyz9 |  *  |       |       |       |       |         |         |                          |
                                  | 1XYz9 |  *  |       |       |       |       |         |         |                          |
                                  | 1XyZ9 |  *  |       |       |       |       |         |         |                          |
                                  | 1XYZ9 |  *  |       |       |       |       |         |         |                          |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  
                                  
                                  +-------+------------------------------------------------------------------------------------+
                                  |       |       Option "Match case"  ON       and       Regex, below, PRECEDED by (?-i)      |
                                  | Text  |-----+-------+-------+-------+-------+---------+---------+--------------------------|
                                  |       | xYZ | xYZ\> | xYZ\b | \<xYZ | \bxYZ | \<xYZ\> | \bxYZ\b | (^|(?<=\W))xYZ((?=\W)|$) |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | xyz   |     |       |       |       |       |         |         |                          |
                                  | xYz   |     |       |       |       |       |         |         |                          |
                                  | xyZ   |     |       |       |       |       |         |         |                          |
                                  | xYZ   |  *  |   *   |   *   |   *   |   *   |    *    |    *    |            *             |
                                  | Xyz   |     |       |       |       |       |         |         |                          |
                                  | XYz   |     |       |       |       |       |         |         |                          |
                                  | XyZ   |     |       |       |       |       |         |         |                          |
                                  | XYZ   |     |       |       |       |       |         |         |                          |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | 1xyz  |     |       |       |       |       |         |         |                          |
                                  | 1xYz  |     |       |       |       |       |         |         |                          |
                                  | 1xyZ  |     |       |       |       |       |         |         |                          |
                                  | 1xYZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                  | 1Xyz  |     |       |       |       |       |         |         |                          |
                                  | 1XYz  |     |       |       |       |       |         |         |                          |
                                  | 1XyZ  |     |       |       |       |       |         |         |                          |
                                  | 1XYZ  |     |       |       |       |       |         |         |                          |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | xyz9  |     |       |       |       |       |         |         |                          |
                                  | xYz9  |     |       |       |       |       |         |         |                          |
                                  | xyZ9  |     |       |       |       |       |         |         |                          |
                                  | xYZ9  |  *  |       |       |   *   |   *   |         |         |                          |
                                  | Xyz9  |     |       |       |       |       |         |         |                          |
                                  | XYz9  |     |       |       |       |       |         |         |                          |
                                  | XyZ9  |     |       |       |       |       |         |         |                          |
                                  | XYZ9  |     |       |       |       |       |         |         |                          |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | 1xyz9 |     |       |       |       |       |         |         |                          |
                                  | 1xYz9 |     |       |       |       |       |         |         |                          |
                                  | 1xyZ9 |     |       |       |       |       |         |         |                          |
                                  | 1xYZ9 |  *  |       |       |       |       |         |         |                          |
                                  | 1Xyz9 |     |       |       |       |       |         |         |                          |
                                  | 1XYz9 |     |       |       |       |       |         |         |                          |
                                  | 1XyZ9 |     |       |       |       |       |         |         |                          |
                                  | 1XYZ9 |     |       |       |       |       |         |         |                          |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  
                                  
                                  +-------+------------------------------------------------------------------------------------+
                                  |       |       Option "Match case"  OFF       and       Regex, below, PRECEDED by (?-i)     |
                                  | Text  |-----+-------+-------+-------+-------+---------+---------+--------------------------|
                                  |       | xYZ | xYZ\> | xYZ\b | \<xYZ | \bxYZ | \<xYZ\> | \bxYZ\b | (^|(?<=\W))xYZ((?=\W)|$) |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | xyz   |     |       |       |       |       |         |         |                          |
                                  | xYz   |     |       |       |       |       |         |         |                          |
                                  | xyZ   |     |       |       |       |       |         |         |                          |
                                  | xYZ   |  *  |   *   |   *   |   *   |       |    *    |    *    |            *             |
                                  | Xyz   |     |       |       |       |       |         |         |                          |
                                  | XYz   |     |       |       |       |       |         |         |                          |
                                  | XyZ   |     |       |       |       |       |         |         |                          |
                                  | XYZ   |     |       |       |       |       |         |         |                          |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | 1xyz  |     |       |       |       |       |         |         |                          |
                                  | 1xYz  |     |       |       |       |       |         |         |                          |
                                  | 1xyZ  |     |       |       |       |       |         |         |                          |
                                  | 1xYZ  |  *  |   *   |   *   |       |       |         |         |                          |
                                  | 1Xyz  |     |       |       |       |       |         |         |                          |
                                  | 1XYz  |     |       |       |       |       |         |         |                          |
                                  | 1XyZ  |     |       |       |       |       |         |         |                          |
                                  | 1XYZ  |     |       |       |       |       |         |         |                          |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | xyz9  |     |       |       |       |       |         |         |                          |
                                  | xYz9  |     |       |       |       |       |         |         |                          |
                                  | xyZ9  |     |       |       |       |       |         |         |                          |
                                  | xYZ9  |  *  |       |       |   *   |       |         |         |                          |
                                  | Xyz9  |     |       |       |       |       |         |         |                          |
                                  | XYz9  |     |       |       |       |       |         |         |                          |
                                  | XyZ9  |     |       |       |       |       |         |         |                          |
                                  | XYZ9  |     |       |       |       |       |         |         |                          |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  | 1xyz9 |     |       |       |       |       |         |         |                          |
                                  | 1xYz9 |     |       |       |       |       |         |         |                          |
                                  | 1xyZ9 |     |       |       |       |       |         |         |                          |
                                  | 1xYZ9 |  *  |       |       |       |       |         |         |                          |
                                  | 1Xyz9 |     |       |       |       |       |         |         |                          |
                                  | 1XYz9 |     |       |       |       |       |         |         |                          |
                                  | 1XyZ9 |     |       |       |       |       |         |         |                          |
                                  | 1XYZ9 |     |       |       |       |       |         |         |                          |
                                  +-------+-----+-------+-------+-------+-------+---------+---------+--------------------------+
                                  

                                  From these results, we can deduce than the N++ Boost regex engine lacks to match 4 ( or 8 ) cases, ONLY IF the four conditions, below, occur, simultaneously :

                                  • The Match case option, of the Find dialog, is ON

                                  • A (?i) modifier starts the regex

                                  • The regex begins with the \< assertion

                                  • The text, to match, begins with an UPPER letter


                                  Luckily :

                                  • The regex \<xYZ can be changed by the regex \bxYZ

                                  • The regex \<xYZ\> can be changed by the regex \bxYZ\b

                                  And note that :

                                  • The assertion \< may be replaced by the assertion (^|(?<=\W))

                                  • The assertion \> may be replaced by the assertion ((?=\W)|$)

                                  Cheers

                                  guy038

                                  BTW, Claudia, when you said :

                                  I agree, I assumed too, that using the modifiers overrules the flags but with the regex
                                  you used we see it isn’t.

                                  I disagree ! Indeed :

                                  Considering the text below :

                                  xyz
                                  xYz
                                  xyZ
                                  xYZ
                                  Xyz
                                  XYz
                                  XyZ
                                  XYZ
                                  

                                  Of course, the two regexes (?i)\<xYZ and (?i)\<xYZ\>, with the Match case option ON, match the first four cases, only

                                  But, the two regexes (?i)\<XYZ and (?i)\<XYZ\>, with the Match case option ON, ALSO match the first four cases, only !

                                  So, I do think that the in-line modifiers (?i) and (?-i) have ALWAYS priority over the Match case option

                                  And, like you, I rather think that it’s just a bug [ in the implementation ] of the Boost regex engine !

                                  Besides, the two regexes (?i)\bxYZ and (?i)\bxYZ\b, with the Match case option ON, correctly match the eight cases, above, of the string “xyz” :-)) => The (?i) modifier forces the insensitive search !

                                  1 Reply Last reply Reply Quote 1
                                  • C
                                    Claudia Frank
                                    last edited by Feb 11, 2017, 10:21 PM

                                    Hi Guy,

                                    thx for your effort on this but I have to disagree with your disagree ;-D

                                    From regex execution point of view there are two ways to change
                                    the case behavior. Either by providing a flag or using the in-line modifiers.
                                    When providing the flag everything is ok (at least for the moment) - so
                                    I have to assume that the regex engine works correctly in this case.
                                    When providing the in-line modifier and the flags then it isn’t ok always.
                                    This does mean there is a bug and it must be related to how in-line modifiers
                                    are handled against flags. And that makes me think that the bug is when doing
                                    this overwrite - which means we can’t rely on it. Maybe other in-line modifiers
                                    together with some special regex constructs behave wrong as well.

                                    Cheers
                                    Claudia

                                    1 Reply Last reply Reply Quote 0
                                    • G
                                      guy038
                                      last edited by guy038 Feb 12, 2017, 9:09 AM Feb 12, 2017, 9:07 AM

                                      Hello, Claudia and All,

                                      Hum…,finally, Claudia, I think that you’re right :-) Indeed, if we built the general table, below, which recapitulates the main cases, it’s obvious that :

                                      • Results are OK, when the “Match case” flag, is ONLY used, WITHOUT any in-line modifier ( Lines 1 and 4 )

                                      • Results seem OK, ( UP TO NOW ), when the “Match case” flag is used, with a starting (?-i) in-line modifier ( Lines 3 et 6 )

                                      • Results seem OK, ( UP TO NOW ), when the “Match case” flag is OFF, with a starting (?i) in-line modifier ( Line 2 )

                                      • Results are NOT OK, when the “Match case” flag is ON, with a starting (?i) in-line modifier and a regex which begins with the \< assertion ( Line 5 )

                                      Luckily, this LAST case ( Line 5 ) is rather rare and does not occur if we use the \b syntax, instead of \< :-))

                                      +=======+=======================+====================+===========+==================+
                                      |  Row  |   "Match case" flag   |  In-line modifier  |  Results  |     Remarks      |
                                      +=======+=======================+====================+===========+==================+
                                      |   1   |          OFF          |         NO         |  Correct  |  Implicit (?i)   |
                                      +-------+-----------------------+--------------------+-----------+------------------+
                                      |   2   |          OFF          |        (?i)        |  Correct  |                  |
                                      +-------+-----------------------+--------------------+-----------+------------------+
                                      |   3   |          OFF          |        (?-i)       |  Correct  |                  |
                                      +=======+=======================+====================+===========+==================+
                                      |   4   |          ON           |         NO         |  Correct  |  Implicit (?-i)  |
                                      +-------+-----------------------+--------------------+-----------+------------------+
                                      |   5   |          ON           |        (?i)        |  PROBLEM  |  IF use of \<    |
                                      +-------+-----------------------+--------------------+-----------+------------------+
                                      |   6   |          ON           |        (?-i)       |  Correct  |                  |
                                      +=======+=======================+====================+===========+==================+
                                      

                                      Cheers,

                                      guy038

                                      1 Reply Last reply Reply Quote 0
                                      • A
                                        Alan Kilborn
                                        last edited by Feb 12, 2017, 1:20 PM

                                        First of all, it is great to see such rousing discussion about the issue I discovered! :-) Thanks to all for that.

                                        There are lots of things to think about coming out of this discussion, but the most obvious and immediate one is a question for Mr Guy: You keep suggesting to use \b instead of \< , but they are not always equivalent, correct? They may be equivalent for certain examples, but in the most general case I believe they are different. If they weren’t different, there would be no reason for both to exist in the N++/Boost engine…

                                        I mean, even I discussed using \b instead in my very first posting in this thread, but that was just as a test, not necessarily a blanket substitution. I guess I don’t want others reading this thread to takeaway that \b and \< are the exact same thing.

                                        Comments? Thoughts?

                                        1 Reply Last reply Reply Quote 0
                                        • M
                                          MAPJe71
                                          last edited by Feb 12, 2017, 1:36 PM

                                          See reference on Word Boundaries for

                                          • description on differences between \b, \< and \>;
                                          • which “engine” supports what.
                                          1 Reply Last reply Reply Quote 0
                                          14 out of 25
                                          • First post
                                            14/25
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors