• Login
Community
  • Login

how is npp's regex different from https://regex101.com/ regex?

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
24 Posts 5 Posters 6.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.
  • M
    Meta Chuh moderator @V S Rawat
    last edited by Meta Chuh Feb 10, 2019, 4:39 PM Feb 10, 2019, 4:30 PM

    @V-S-Rawat

    the main difference, which might be relevant to you, as i’ve seen in the past, is the /.

    in pcre/php, a regex is usually started and ended with a “/” as delimiter, followed by modifiers m, s, i, etc.
    (you can find an explanation of pcre modifiers >>> here <<< )
    example of a pcre regex string: /^(.*?)search_string(.*?)$/msi

    therefore all / used in your regex search have to be escaped as \/ if you use it in pcre

    in notepad++ your input field is just the pure regex that would be inside the two / of pcre, and modifiers are usually set separately, like checking of match case instead of leaving out the i in the pcre regex string.

    as you just input the pure regex, without delimiters or modifiers in the npp search field, it’s best to watch out for all occurrences of an escaped \/ and replace them with an unescaped /

    so a pcre search string like:
    /^(.*?)my\/path\/to\/my.exe/msi

    would have to be adapted for notepad++ like this:
    ^(.*?)my/path/to/my.exe

    A V 2 Replies Last reply Feb 10, 2019, 7:26 PM Reply Quote 2
    • M
      MAPJe71
      last edited by Feb 10, 2019, 5:27 PM

      FYI:

      1. one has to distinguish two uses of “PCRE”:
        a. the name of a regular expression engine library (its successor is called PCRE2);
        b. indicating a regular expression engine library is PERL Compatble;
      2. the official release of Notepad++ is compiled including the Boost Regex library which can be (and is) configured as a PERL Compatible Regular Expression (PCRE) engine;
      3. Notepad++ compiled without Boost uses the RE engine as included with Scintilla which is ECMAScript (JavaScript) compatible;
      1 Reply Last reply Reply Quote 5
      • A
        Alan Kilborn @Meta Chuh
        last edited by Feb 10, 2019, 7:26 PM

        @Meta-Chuh

        It may be worth noting that the /.../xyz style that regex101 uses has an analog in Notepad++ regex syntax that looks like this: (?xyz-uvw).... where features xyz would be turned ON as shown and features uvw would be turned OFF. Note that xyz and uvw aren’t real features, just trying to demo the syntax. This usage in Notepad++ usually leads off the regex (athough it can happen in the middle to affect only what comes after) and overrides the settings of any of the UI checkboxes. Useful features for N++ are:

        i or -i : ignore case or match case, respectively
        s or -s : single line mode or not, respectively (allows . to match a line-ending character, or not)
        m or -m : multiple line mode or not, respectively (not sure the usefulness of this, TBH, maybe in the link above?)
        x : ignore whitespace in regex for a more pleasing visual experience

        M 1 Reply Last reply Feb 10, 2019, 7:38 PM Reply Quote 2
        • M
          Meta Chuh moderator @Alan Kilborn
          last edited by Meta Chuh Feb 10, 2019, 7:40 PM Feb 10, 2019, 7:38 PM

          @Alan-Kilborn

          It may be worth noting …

          maybe, but maybe not for @V-S-Rawat.

          the last time i gave him an extensive answer, about how to test notepad++ commits, he politely slowed me down a bit and said, that it was too much information for him.

          so i stick to the minimised information that might be of relevance for him, always knowing that he will ask if he needs anything more.

          i quote:

          @V-S-Rawat said: (By any chance, are you believing me to be a computer wizard? Wrong assumption, dear sir :-) )

          A V 2 Replies Last reply Feb 10, 2019, 8:42 PM Reply Quote 2
          • A
            Alan Kilborn @Meta Chuh
            last edited by Feb 10, 2019, 8:42 PM

            @Meta-Chuh

            Well, we are also posting for others that might see and learn something, not just the OP. :)

            M 1 Reply Last reply Feb 10, 2019, 8:50 PM Reply Quote 1
            • M
              Meta Chuh moderator @Alan Kilborn
              last edited by Feb 10, 2019, 8:50 PM

              @Alan-Kilborn

              i just try to avoid getting reprehended again by trying to learn how to correctly respond to users i know 😉

              note: if you want it to address it to all others, you can add “and all” as a suffix to the @Meta-Chuh tag, or, if it is originally not meant for me, don’t use my tag at all.

              1 Reply Last reply Reply Quote 1
              • A
                Alan Kilborn
                last edited by Feb 11, 2019, 1:15 AM

                @Meta-Chuh (meant for you!):

                Sure. If it is in direct reply to something you pointed out, I hit the small reply next to your posting. If it is a generic reply, I press the blue Reply button below all postings. I think “and all” might be a bit redundant, as anybody interested can read any reply without being directly invited to. :)

                1 Reply Last reply Reply Quote 2
                • V
                  V S Rawat @Alan Kilborn
                  last edited by Feb 11, 2019, 8:20 AM

                  @Alan-Kilborn Yes, I was looking for some free site which gives regex testing totally compatible with npp. :-(

                  1 Reply Last reply Reply Quote 0
                  • V
                    V S Rawat @Eko palypse
                    last edited by Feb 11, 2019, 8:23 AM

                    @Eko-palypse I am newbie to regex so I face problem in formulating them.

                    npp doesn’t provide any help in developing a regex as it doesn’t tell what is wrong where.

                    I wanted some site like the one mentioned that would give regex that would run 100% “as such” in npp.

                    As that site is also having a “python” flavor of regex mentioned, I think pythonscript plugin’s regex would also be different from regex that would run from npp’s default find replace.

                    1 Reply Last reply Reply Quote 0
                    • V
                      V S Rawat @Meta Chuh
                      last edited by Feb 11, 2019, 8:25 AM

                      @Meta-Chuh said:

                      @V-S-Rawat

                      the main difference, which might be relevant to you, as i’ve seen in the past, is the /.

                      in pcre/php, a regex is usually started and ended with a “/” as delimiter, followed by modifiers m, s, i, etc.
                      (you can find an explanation of pcre modifiers >>> here <<< )
                      example of a pcre regex string: /^(.*?)search_string(.*?)$/msi

                      therefore all / used in your regex search have to be escaped as \/ if you use it in pcre

                      in notepad++ your input field is just the pure regex that would be inside the two / of pcre, and modifiers are usually set separately, like checking of match case instead of leaving out the i in the pcre regex string.

                      as you just input the pure regex, without delimiters or modifiers in the npp search field, it’s best to watch out for all occurrences of an escaped \/ and replace them with an unescaped /

                      so a pcre search string like:
                      /^(.*?)my\/path\/to\/my.exe/msi

                      would have to be adapted for notepad++ like this:
                      ^(.*?)my/path/to/my.exe

                      Yes, that was the main difference I had observed. Clarifying that was indeed helpful.

                      Thanks.

                      1 Reply Last reply Reply Quote 1
                      • V
                        V S Rawat @Meta Chuh
                        last edited by Feb 11, 2019, 8:28 AM

                        @Meta-Chuh said:

                        the last time i gave him an extensive answer, about how to test notepad++ commits, he politely slowed me down a bit and said, that it was too much information for him.

                        :-) Sorry for that. I am a newbie at regex, and my growing age is blunting my quick learning. Smaller bites help me. :-)

                        Thanks for considerations.

                        1 Reply Last reply Reply Quote 1
                        • V
                          V S Rawat
                          last edited by Feb 11, 2019, 8:33 AM

                          That brings me to an idea.

                          I assume that these regex libraries are available ready to be compiled with apps and are for free.

                          In that case, can boost regex library be removed from npp and can npp be compiled with other such libraries?

                          Can a user do it if npp code is available?

                          Or can I ask for this a new feature in regex that npp is compiled will “ALL” libraries of regex, and find/ replace window gets a new option of "what type of regex (“PCRE/ Pyton/ Java/…)?”

                          That will probably make npp the only editor that has option to use all types of regex at the tick of a check box.

                          What would be pros and cons of that?

                          M 1 Reply Last reply Feb 11, 2019, 9:55 AM Reply Quote 1
                          • V
                            V S Rawat
                            last edited by Feb 11, 2019, 8:36 AM

                            Also, as @Eko-palypse shared above, pythonscript provides its own regex tester, which is different from npp’s default boost regex library,

                            so, can flavors of all type of regex libraries be supplied as a plug-in (or one for one plug-in) to be used with npp?

                            I can’t do that, maybe a hint for plug-in developers.

                            E 1 Reply Last reply Feb 11, 2019, 12:17 PM Reply Quote 1
                            • M
                              Meta Chuh moderator @V S Rawat
                              last edited by Feb 11, 2019, 9:55 AM

                              @V-S-Rawat

                              btw: @MAPJe71 recently posted a free offline regex tester tool .

                              @MAPJe71 wrote: Additional Regex Tester tool (offline): RegEx Tester

                              maybe this tool can be of interest for you too.

                              V 1 Reply Last reply Feb 11, 2019, 10:34 AM Reply Quote 1
                              • V
                                V S Rawat @Meta Chuh
                                last edited by Feb 11, 2019, 10:34 AM

                                @Meta-Chuh promptly downloaded that. shall test when next requirement comes up.

                                maybe, npp developers can crack an arrangement with @MAPJe71 to bundle the tester zipfile with npp installer.

                                1 Reply Last reply Reply Quote 0
                                • E
                                  Eko palypse @V S Rawat
                                  last edited by Eko palypse Feb 11, 2019, 12:18 PM Feb 11, 2019, 12:17 PM

                                  @V-S-Rawat said:

                                  Also, as @Eko-palypse shared above, pythonscript provides its own regex tester, which is different from npp’s default boost regex library,

                                  True, but the closest you can get at the moment - as far as I know.
                                  One question you haven’t answered, or I have over read, is what you are doing with the regex at the end.
                                  If you use the find replace dialog then non of the solution will 100% fit and the closest might be
                                  the RegexTester from PythonScript plugin.
                                  If you want to use the regex within a PythonScript plugin then RegexTester matches 100% .

                                  The idea of having all regex engines in one product is a nice idea but doesn’t guarantee it is always
                                  like it is in npp. Just a note, C++ (14/17 ??) has now its own regex engine as well.

                                  A V 2 Replies Last reply Feb 11, 2019, 1:25 PM Reply Quote 1
                                  • A
                                    Alan Kilborn @Eko palypse
                                    last edited by Feb 11, 2019, 1:25 PM

                                    @Eko-palypse said:

                                    If you want to use the regex within a PythonScript plugin then RegexTester matches 100%

                                    This is because RegexTester is written in Pythonscript itself, and calls the regex engine of Pythonscript, which is NOT the Python regex engine.

                                    I have done some research and it is my understanding from reading some earlier postings here as well as the product description, that Regex Buddy is the best regex tester, but it is not free. It can directly use the Boost regex engine that is a close to what is in Notepad++ as one can get. Regarding not free: It depends how much time you waste having regex problems currently. It does not take much time of that sort before such a program pays for itself. And so we’re clear, I have no affiliation with Regex buddy.

                                    M 1 Reply Last reply Feb 11, 2019, 10:07 PM Reply Quote 4
                                    • M
                                      Meta Chuh moderator @Alan Kilborn
                                      last edited by Feb 11, 2019, 10:07 PM

                                      off topic, but important: @Alan-Kilborn

                                      could you please have a look at this topic link below ?

                                      https://notepad-plus-plus.org/community/topic/17072/new-enhancement-for-user-defined-language-system/15

                                      this is very strange, as the nodebb db got scrambled somehow.
                                      it was the topic where we were talking about udl manuals, and one of your posts disappeared.

                                      further more, the id’s got mixed up and out of alignment, so that instead of your post, we see rddim.

                                      and most weird thing: my answer to your post has your name now, which is completely out of context.

                                      afaik i suppose that it wasn’t done by the mods, as there was no reason what so ever to delete any of the posts, especially not yours.

                                      did you by any chance accidentally or willingly delete it yourself ?
                                      if yes, there could be some sort of bbs db bug.

                                      note: please don’t delete this “hybrid post mixup”, because it is not yet known, if someone might need it for any investigations.
                                      i’ve already notified don & co. about that.

                                      A 1 Reply Last reply Feb 12, 2019, 12:35 AM Reply Quote 1
                                      • A
                                        Alan Kilborn @Meta Chuh
                                        last edited by Feb 12, 2019, 12:35 AM

                                        @Meta-Chuh

                                        Strange indeed. I deleted nothing, accidentally or willingly. I do now see that a posting that is clearly authored by you is attributed to me. Maybe I look smart now. :)

                                        1 Reply Last reply Reply Quote 3
                                        • V
                                          V S Rawat @Eko palypse
                                          last edited by Feb 12, 2019, 11:09 AM

                                          @Eko-palypse

                                          I use regex in npp as a normal text cleaning. removing unwanted text, breaking lines at certain places “, ; . etc.”, joining them back after certain processing.

                                          I don’t use regex in pythonscript, because I don’t know much of pythonscript.

                                          several things I do is repetitive, I have to do the same set, with slight changes for numbers, etc., to break the text again and again, and join back again and again after processing, that’s why I had thought to make pythonscripts for repeated use, and I had installed the plugin.

                                          But I tried for somedays and couldn’t make much headway so I gave up. Now only one pythonscript is there for repeated things.

                                          some day I will gather courage again to learn pythonscript, till then it is find-replace regex on text.

                                          1 Reply Last reply Reply Quote 0
                                          14 out of 24
                                          • First post
                                            14/24
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors