• Login
Community
  • Login

Replace character in capture group

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
28 Posts 7 Posters 4.6k 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.
  • A
    Alan Kilborn @M Andre Z Eckenrode
    last edited by Alan Kilborn Oct 30, 2020, 11:14 PM Oct 30, 2020, 11:13 PM

    @M-Andre-Z-Eckenrode said in Replace character in capture group:

    I can’t get any of the syntaxes

    If I use this as the replace-with expression for your search-for expression and data:

    find: ABC(?<Name>.+?)XYZ
    repl: abc_$+{Name}_xyz
    data to search: ABCDEFGHIJKLMNOPQRSTUVWXYZ

    I obtain:

    abc_DEFGHIJKLMNOPQRSTUVW_xyz

    I tell you that because you were asking about “replacement expression”.

    However, your examples show you were trying to use \g which I believe only works in the find expression. Example:

    find: (?<Name>t...)ING\g<Name>

    which would match:

    data to search: testINGtest or testINGtrip

    A similar but distinctly different example:

    find: (?<Name>t...)ING(?&Name)

    which would match:

    data to search: testINGtest or tripINGtrip but not testINGtrip

    P M 2 Replies Last reply Oct 30, 2020, 11:51 PM Reply Quote 1
    • P
      PeterJones @Alan Kilborn
      last edited by Oct 30, 2020, 11:51 PM

      @M-Andre-Z-Eckenrode ,

      I can’t get any of the syntaxes listed … Replacement Expression

      @Alan-Kilborn said in Replace character in capture group:

      I believe only works in the find expression

      You are correct.

      And you weren’t the first person this week to not notice that the \g and \k syntaxes are in the search section, and not in the replacement section (which tried to be explicit that any syntax not mentioned in the replacement section was not valid in the replacement field, but has apparently failed).

      Could you both look at the proposed capture groups and backreferences phrasing and substitution phrasing , and make sure that the updated sections makes the distinction more clear?

      —
      Note to future readers: those “phrasing” links are to a temporary branch, and in the future, they will not work. https://npp-user-manual.org/docs/searching/ is the official location of the search documentation, and https://github.com/notepad-plus-plus/npp-usermanual/blob/master/content/docs/searching.md is the master github source for the document.

      M 1 Reply Last reply Oct 31, 2020, 12:50 AM Reply Quote 0
      • M
        M Andre Z Eckenrode @Alan Kilborn
        last edited by Oct 30, 2020, 11:58 PM

        @Alan-Kilborn said in Replace character in capture group:

        repl: abc_$+{Name}_xyz
        your examples show you were trying to use \g which I believe only works in the find expression.

        Aha! Looks that’s true in NPP — though \g<Name> actually DOES work in PCRE replacement expressions at Regex101 .

        Thanks for the education.

        A 1 Reply Last reply Oct 31, 2020, 12:18 AM Reply Quote 0
        • A
          Alan Kilborn @M Andre Z Eckenrode
          last edited by Oct 31, 2020, 12:18 AM

          @M-Andre-Z-Eckenrode

          DO NOT rely on regex101 for the more esoteric aspects of regex. Doing so, and then intending to use the results in Notepad++ will cause frustration. Sure, okay, for simple cases, but the caliber of stuff you have been discussing in this thread is going to be different in N++ and regex101.

          M 1 Reply Last reply Oct 31, 2020, 12:56 AM Reply Quote 1
          • M
            M Andre Z Eckenrode @PeterJones
            last edited by Oct 31, 2020, 12:50 AM

            @PeterJones said in Replace character in capture group:

            Could you both look at the proposed capture groups and backreferences phrasing and substitution phrasing , and make sure that the updated sections makes the distinction more clear?

            Looks good to me so far, though coming from a fairly green regex user like me, I’d take that with a grain of salt. :-)

            On a tangent here, I’ve noticed, on occasion when doing find/replace operations, that the In selection checkbox was sometimes ghosted (not available to check or uncheck), which I keep meaning to compile a list of circumstances for presentation and inquiry in these forums sometime. I notice that in both official and proposed versions of the doc, there seems to be no mention of any limitations on when the In selection checkbox is available. There seem to be some known limitations (at least one of which is mentioned here). Maybe they should be added to the docs?

            A P 2 Replies Last reply Oct 31, 2020, 1:03 AM Reply Quote 1
            • M
              M Andre Z Eckenrode @Alan Kilborn
              last edited by Oct 31, 2020, 12:56 AM

              @Alan-Kilborn said in Replace character in capture group:

              the caliber of stuff you have been discussing in this thread is going to be different in N++ and regex101.

              I think I’ve already made it fairly clear, in my previous posts to this thread, that that’s what I’m finding to be the case.

              A 1 Reply Last reply Oct 31, 2020, 12:59 AM Reply Quote 0
              • A
                Alan Kilborn @M Andre Z Eckenrode
                last edited by Oct 31, 2020, 12:59 AM

                @M-Andre-Z-Eckenrode said in Replace character in capture group:

                I think I’ve already made it fairly clear, in my previous posts to this thread, that that’s what I’m finding to be the case.

                Perhaps, but I get the feeling you might be holding on to regex101 a bit much. :-)

                Plus, I’m kind of a late joiner to this thread; there’s a lot of content.

                1 Reply Last reply Reply Quote 0
                • A
                  Alan Kilborn @M Andre Z Eckenrode
                  last edited by Alan Kilborn Oct 31, 2020, 1:04 AM Oct 31, 2020, 1:03 AM

                  @M-Andre-Z-Eckenrode said in Replace character in capture group:

                  In selection checkbox was sometimes ghosted

                  In selection checkbox enabled condition: A single selection of one or more characters, that is NOT a column block selection.

                  Note that the checkbox’s appearance status can only be relied upon when you actually switch input focus to the find (family) window – upon activation the code runs a check to make sure you have the proper type of selection, and updates the checkbox and its state at that time.

                  1 Reply Last reply Reply Quote 1
                  • P
                    PeterJones @M Andre Z Eckenrode
                    last edited by Oct 31, 2020, 4:53 PM

                    @M-Andre-Z-Eckenrode said in Replace character in capture group:

                    Looks good to me so far

                    Thanks. Submitted PR #127. Hopefully, it will make it in before the next release of the npp-user-manual.org website.

                    A 1 Reply Last reply Oct 31, 2020, 5:52 PM Reply Quote 0
                    • A
                      Alan Kilborn @PeterJones
                      last edited by Alan Kilborn Oct 31, 2020, 5:53 PM Oct 31, 2020, 5:52 PM

                      @PeterJones said in Replace character in capture group:

                      Looks good to me so far

                      Looked fine to me as well.
                      Thanks for your fine attention to the manual.
                      I just need to read it more when I have trouble with things. :-)

                      1 Reply Last reply Reply Quote 1
                      • G
                        guy038
                        last edited by Nov 2, 2020, 9:44 PM

                        Hello, @peterjones,

                        Sorry, I’ve just seen your post where you asked people to verify the N++ official documentation ! I’ll try to have a look, myself, very soon. It would be better to do it before the next release of the website !

                        But, as I said to Alan, at the moment, my TO DO list, concerning N++ or else, is getting much longer ;-))

                        Cheers,

                        guy038

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